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.
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!
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
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.