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

    Hi, I would like the page title (H1) within blog posts automatically be the name of the category the post resides in. Is this possible?

    So for example: if my blog post’s title is “Name of the hinduism” and the category is “Introduction to the hinduism”, H1 should be “Introduction to the Hinduism” and H2 “Name of the Hinduism”.

    I hope you can help me out.

    #472154

    Hey InspireCreations!

    Thank you for using Enfold.

    You can try this in the functions.php file:

    add_filter('avf_title_args', 'avf_portfolio_title_args', 10, 1);
    function avf_portfolio_title_args($args) { 	
    
    	$title = get_the_title($id);
    
    	if(is_singular('portfolio') && is_single()) {
    		$terms = get_the_terms( $id, 'portfolio_entries' );
    	}elseif(is_singular('post')){
    		$terms = get_the_terms( $id, 'category' );
    	}
    	
    	if(is_singular(array('portfolio', 'post')) && is_single()) {
    		$portfoliocat = array();
    		foreach ( $terms as $term ) {
    			$portfoliocat[] = $term->name;
    		}	
    		$args['title']    = $portfoliocat[0];	
    	} else {	
    		$args['title']    = $title;
    	}
    
    	return $args;
    }

    This code will get the first category of the post.

    Cheers!
    Ismael

    #483575

    Thank you! It seems to work :)

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘H1 to show category’ is closed to new replies.