Hello,
We apologize for the issue you are facing with the breadcrumbs and product categories. It seems that you want to display both the primary category and its child category in the breadcrumbs, but currently, it only shows the primary category.
In Rank Math, when you have a primary category selected, it will prioritize that category in the breadcrumbs. Unfortunately, there isn’t a way to deselect the primary category without selecting another one, as you’ve noted.
To achieve the breadcrumb structure you desire (e.g., Sunglasses > Men's > Product name), you may need to ensure that the child category is set as the primary category for that specific product. If you want to show both categories, consider setting the child category as the primary category instead of the parent category.
If you need further assistance or if this doesn’t resolve your issue, please reply to this ticket, and a human agent from the Rank Math Support team will take over and assist you further.
Thank you for raising this concern!
Sources:
How to Enable Breadcrumbs on Your Website With Rank Math SEO » Rank Math
Hello,
You can use the following filter on your website to show all the categories on Breadcrumbs:
add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
if ( is_single() ) {
$category = get_the_category();
if ( count( $category ) > 0 ) {
$cat_array = array();
$count = 0;
foreach( $category as $cat ) {
$cat_array[$count][0] = $cat->name;
$cat_array[$count][1] = get_category_link( $cat->term_id );
$count++;
}
array_splice($crumbs, 1, 1, $cat_array);
}
}
return $crumbs;
}, 10, 2);
Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how it goes. Looking forward to helping you.
Thank you.
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.