Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
Could you please confirm if you wanted to show the Home – Shop only on the breadcrumbs of your child category pages?
If so, you can hide the parent category via disabling this option in Rank Math > General Settings > Breadcrumbs:
https://rankmath.com/kb/general-settings/#show-category
And here’s a filter you can use to hide the child category title:
add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
if(is_category('childcat')){
unset($crumbs[2]);
}
// And return the breadcrumbs
return $crumbs;
}, 10, 2);
Please update/customize the childcat
to your actual child category slug, and the number in $crumbs[2
] to match the desired result.
And here’s how to apply a filter on your site:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
I hope that helps.
Thank you.
Hi there, Thanks for your reply.
No, that’s not what I mean. On the child page I only want to show the parent page in the breadcrumb.
So Home and Shop and child page should not be visible in the link.
Is this a bit clear?
Hello,
To add/remove items from the Breadcrumbs, please add the following filter to your active theme’s functions.php file:
/**
* 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 ) {
return $crumbs;
}, 10, 2);
Please let us know how that goes. Looking forward to helping you further.
Thak you
when I paste the code into a code snippet nothing happens. I’ve added a screenshot to show what I’m seeing now in the code snippet.
So you see home – Hijab – Jersey now. Jersey is a subcategory of Hijab category. Now I only want to show the Hijab page in the breadcrumb. So page Home and current subcategory page Jersey should not be visible.
https://ibb.co/nPM0PJ8
Hello,
Please add the below filter to your website and see if it gives you the desired output:
add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
$cat = get_queried_object();
if ( !empty($cat->parent) ) {
$newcrumbs = array($crumbs[1]);
return $newcrumbs;
}
return $crumbs;
}, 10, 2);
add_filter( 'rank_math/frontend/breadcrumb/html', function( $html, $crumbs, $class ) {
$cat = get_queried_object();
if ( !empty($cat->parent) ) {
$html = str_replace(
'<span class="last">'.$crumbs[0][0].'</span>',
'<a href="'.$crumbs[0][1].'">'.$crumbs[0][0].'</a>',
$html
);
}
return $html;
}, 10, 3);
You can follow this guide to add the filter:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Looking forward to hearing back from you.
Thank you.
hi there,
now i see only the current page instead of the parent page..
Hello,
We might need to take a closer look at the settings. Please edit the first post on this ticket and include your Affected URL, WordPress & FTP logins in the designated Sensitive Data section.
Please do take a complete backup of your website before sharing the information with us.
It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
We really look forward to helping 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.