Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #256732

    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;
    }

    #257411

    Hi AmarMahallati!

    Where in the functions file did you add in the function and add filter?

    Cheers!
    Devin

    #257452
    #257462

    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

    #257478

    okay the category name appears now but with the home url!
    i need it with category url

    #257486

    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

    #257499

    Thanks Josue

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘how to change Blog – Latest News’ is closed to new replies.