Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1219624

    You recently provided me with some PHP code that could be used to provide the post/portfolio header title in the subject field of an e-mail link. See below that was added to the functions.php file. What I also need is to add to that subject field the Parent Category name of that post/portfolio.

    Can you please help

    <?php
    function custom_shortcode_func() {
            global $post;
    	ob_start();
    ?>	
    		<a href="mailto: (Email address hidden if logged out) ?subject=Purchase Enquiry on <?php echo get_the_title($post->ID);?> Painting">Purchase Enquiry</a>
    <?php	
    
    	$output = ob_get_clean();
        return $output;
    }
    add_shortcode('my_shortcode', 'custom_shortcode_func');
    ?>
    • This topic was modified 4 years, 6 months ago by condonpb.
    #1221686

    Can someone please respond as this is getting urgent

    #1222100

    Hi,

    Please try using the code as following

    function custom_shortcode_func() {
            global $post;
    
            $category = get_the_category(); 
    		$category_parent_id = $category[0]->category_parent;
    		if ( $category_parent_id != 0 ) {
        		$category_parent = get_term( $category_parent_id, 'category' );
        		$parent_cat_slug = $category_parent->slug;
    		} else {
        		$parent_cat_slug = $category[0]->slug;
    		}
    		ob_start();
    ?>	
    		<a href="mailto: (Email address hidden if logged out) ?subject=Purchase Enquiry on <?php echo get_the_title($post->ID);?> Painting from <?php echo $parent_cat_slug; ?> category">Purchase Enquiry</a>
    <?php	
    
    	$output = ob_get_clean();
        return $output;
    }
    add_shortcode('my_shortcode', 'custom_shortcode_func');
    

    Best regards,
    Yigit

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.