Hi,
how to change “Blog – Latest News” to category name on posts page
i tried this but it doesn’t work:
functions.php:
add_filter(‘avf_title_args’, ‘single_blog_page_title’, 10, 2);
function single_blog_page_title($args,$id) {
if( is_single() ) {
$cat = get_the_category($id);
if(isset($category[0])) $args[‘title’] = $category[0]->cat_name;
}
return $args;
}
Hi AmarMahallati!
Where in the functions file did you add in the function and add filter?
Cheers!
Devin
Hey!
Your code is wrong, the $cat and $category variables should be one:
add_filter('avf_title_args', 'single_blog_page_title', 10, 2);
function single_blog_page_title($args,$id) {
if( is_single() ) {
$cat = get_the_category($id);
if(isset($cat[0])) $args['title'] = $cat[0]->cat_name;
}
return $args;
}
Cheers!
Josue
okay the category name appears now but with the home url!
i need it with category url
Hey!
Change your code to:
add_filter('avf_title_args', 'single_blog_page_title', 10, 2);
function single_blog_page_title($args,$id) {
if( is_single() ) {
$cat = get_the_category($id);
$args['title'] = $cat[0]->cat_name;
$args['link'] = get_category_link($cat[0]->term_id);
}
return $args;
}
Regards,
Josue
Thanks Josue