Help with RankMath Breadcrumbs – How to Replace a Category with a Specific Page?

#719683
  • Resolved Leandro Santorsola
    Rank Math free

    Hello RankMath’s team!

    First of all, I just wanted to say thanks for all the support you are giving to the free RankMath community.

    Now, regarding my issue.

    I am basically trying to replace specific categories with specific pages in the breadcrumbs of my website (I am using RankMath of course).

    My current breadcrumb structure is this (I will insert 2 different examples here):

    – home > category1 > category2 > post1
    – home > category1 > category3 > post2

    I want to change this to this format:

    – home > page1 > page2 > post1
    – home > page1 > page3 > post2

    In other words, I want to show the following structure in the breadcrumbs:

    – home > pillar page > sub pillar page > post

    The home and pillar page will always be the same, but the sub pillar page and post will change depending on the post. For example:

    – home > products (pillar page) > shoes (sub pillar page) > best shoes for running (post)
    – home > products (pillar page) > accessories (sub pillar page) > best gloves for snow (post)

    I understand the difference between posts and pages in WordPress and that’s why I am struggling with this in the first place.

    Thanks. Hope someone can help me with this issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    Thank you for reaching out to us, and we appreciate your kind words about our support.

    To replace specific categories with specific pages in the breadcrumbs of your website using Rank Math, you can achieve this by adding custom code snippets to your site. You can use the provided filter to remove categories from being displayed in the breadcrumbs of your posts and pages. Here’s an example of the filter you can use:

    /** 
    * 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[1]); 
              $crumbs = array_values($crumbs);      
              return $crumbs;   
            }   
            return $crumbs; 
    }, 10, 2);

    You can modify this filter to suit your specific needs and replace the categories with the specific pages you want to display in the breadcrumbs.

    If you need further assistance with implementing this or have any other questions, please feel free to ask, and we’ll be happy to help.

    Best regards.

    Sources:
    How to Customize Breadcrumbs in Rank Math » Rank Math
    How to Enable Breadcrumbs on Your Website With Rank Math SEO » Rank Math

    Hello,

    Thank you for your patience.

    In that case, you may need to customize the filter above further to achieve the breadcrumbs structure you have shared.

    Here’s an example filter to get you started:

    /**
     * Allow changing or removing the Breadcrumb items
     *
     * @param array       $crumbs The crumbs array.
     * @param Breadcrumbs $this   Current breadcrumb object.
     */
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
            //Adding to single posts
    	if(is_singular('post')){
                    //pass an array containing the name of the crumb, URL and 
                    //hide_in_schema option	
                    $detail[] = array(
    		'Product', 
                    'https://www.site.com/product-page', 
                    'hide_in_schema' => false
    		);
                    //add this value as the second item in array
    		array_splice( $crumbs, 2, 0, $detail ); 
    		
    		$exterior[] = array(
    		'Shoes', 
                    'https://www.site.com/shoes-page', 
                    'hide_in_schema' => false
    		);
                    //add this value as the second item in array
    		array_splice( $crumbs, 3, 0, $exterior ); 
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);

    And here’s a guide to adding the filter to your website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Help with RankMath Breadcrumbs – How to Replace a Category with a Specific Page?’ is closed to new replies.