Breadcrumbs Help

#691791
  • Resolved Tom Grieve
    Rank Math pro
    Content AI Starter

    Hi,

    I am struggling with an issue I thought would be a common issue.

    1 – I have a link (#1 below) – that goes to a team page. If you look at the associated breadcrumb – it is perfect. (I guess this is a content type: PAGE)

    2 – When I click ON the Contact + BIO button for the first person (ALL people on page react same) – I go to their page. (See #2). Below you can see the page and the Breadcrumb. ( I am guessing this is a content type; CPT – as I use Custom Post Types.)

    3 – The desired breadcrumb path for this individual is posted below (2.5)

    I am really hoping you all can help me out with this. Yoast told me to hire an experience developer. I requested a refund from them. (Not a yoast fan). Just need someone with a little patience to help me out.

    Any help is appreciated! Happy to answer any questions.
    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Tom Grieve
    Rank Math pro
    Content AI Starter

    Still looking for help with this.

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    Apologies for the delay as we currently have a high volume of tickets here in our support forums.

    The Heartland Fabrication Team is indeed a page, that’s why it’s not getting included in the breadcrumbs to support the hierarchical function of your single CPT.

    However, to customize the breadcrumbs and add them when viewing the single CPT, you may use and edit this filter on your site (change the “cpt-name” to the actual CPT name):

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
            //Adding to single posts
    	if(is_singular('cpt-name')){ // change to match the actual custom post type name
                    $value[] = array(
    		'Heartland Fabrication Team', 
                    'https://stg-fabtestsite-fabtest.kinsta.cloud/heartland-fabrication-team/', 
                    'hide_in_schema' => false
    		);
                    //add this value as the second item in array
    		array_splice( $crumbs, 1, 0, $value ); 
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);

    Here is a guide you can follow to add the filter:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how this goes.

    Thank you.

    Tom Grieve
    Rank Math pro
    Content AI Starter

    Reinelle,

    That worked perfectly! WOW! So excited – because I went around with yoast and they told me to “reach out to one of our partners”. (I hate yoast.)

    This has been such a headache.

    New question!
    Do I add a separate filter for each CPT I need to do this too? Or can you add a sample to the above code to show me two or more (I have three in total) – in an array? ( I am NOT a programmer – I just know how to add things to the functions.php page. :^)

    Thank you and let me know!

    Tom Grieve
    Rank Math pro
    Content AI Starter

    Another issue…

    • I then tried to use this solution along with another piece of code to REMOVE the CPT from the breadcrumb.
    • I tried BOTH of these (code segments below) in the same functions.php file and it did not work.
    • Is there a way to get them to both work at the same time?

    #1 – code worked as desired:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
            //Adding to single posts
    	if(is_singular('barge')){ // change to match the actual custom post type name
                    $value[] = array(
    		'Barge Models', 
                    'desired domain path', 
                    'hide_in_schema' => false
    		);
                    //add this value as the second item in array
    		array_splice( $crumbs, 1, 0, $value ); 
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);

    #2 – I then added this code below it:

    /** 
    * 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('barge')){ //Unset elements with key 1 		
              unset($crumbs[1]); 
              $crumbs = array_values($crumbs); 		
              return $crumbs; 	
            } 	
            return $crumbs; 
    }, 10, 2);

    And it reverted the path to the original undesired Breadcrumb. I would like this (page link in sensitive data):
    Current Breadcrumb:
    Home » Barge Models » B-36 | Covered Hopper Rake Barge

    Desired Breadcrumb:
    Home » Barge Models » Barges » B-36 | Covered Hopper Rake Barge

    Tom Grieve
    Rank Math pro
    Content AI Starter

    I fixed the issue by reversing the order of the filters in the functions.php.

    Hello,

    Thank you for the update.

    We’re glad that you have already managed to resolve the breadcrumbs issue on your site.

    If you have any other concerns, please don’t hesitate to contact us anytime to assist you further.

    Looking forward to helping you.

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

The ticket ‘Breadcrumbs Help’ is closed to new replies.