HELP ME TO CUSTOM BREADCRUMB

#718635
  • Resolved Anonymous
    Rank Math free

    My breadcrumb includes category.
    I only want to display Home > Blog > Title of the post, but my breadcrumbs always shows Home > Blog > Category > Title of the post.
    I have followed the guideline in this website: https://rankmath.com/kb/customize-breadcrumbs-in-rank-math/

    Past the code below into function.php, but it does not work. My breadcrumb displays like Home > Category > Title of the post. So please help me to find way to remove category in my breadcrumb

    The code:
    /**
    * Filter to display tags in Rank Math Breadcrumbs.
    */
    add_filter( ‘rank_math/frontend/breadcrumb/items’, function( $crumbs, $class ) {
    $get_post_tags = get_the_tags();

    if ($get_post_tags) {
    foreach($get_post_tags as $tag) {
    $tag_list= [ $tag->name, get_tag_link( $tag->term_id ) ];
    array_splice( $crumbs, 2, 0, array($tag_list) );
    }
    }
    return $crumbs;
    }, 10, 2);

Viewing 1 replies (of 1 total)
  • Hello, I’m sorry to hear that you’re facing issues with customizing your breadcrumbs. It seems like the code snippet you’ve added to your functions.php file is not achieving the desired result of removing the category from your breadcrumbs.

    To remove the category from your breadcrumbs, you can use the following code snippet:

    /** 
    * Filter to remove categories from Rank Math Breadcrumbs. 
    */ 
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) { 
            // check if we are viewing single posts
    
            if(is_singular('post')){ //Unset elements with key 1        
              unset($crumbs[2]); // Change the index to remove the category
              $crumbs = array_values($crumbs);      
              return $crumbs;   
            }   
            return $crumbs; 
    }, 10, 2);

    Please replace the existing code in your functions.php file with the code provided above. This should remove the category from being displayed in the breadcrumbs of your posts.

    If you encounter any further issues or need additional assistance, please feel free to let us know. We’re here to help!

    Sources:
    How to Customize Breadcrumbs in Rank Math » Rank Math
    How to Fix “Either ‘name’ or ‘item.name’ should be specified” Error » Rank Math

Viewing 1 replies (of 1 total)

You must be logged in to reply to this ticket.