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.
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
Thank you! It seems to work :)