Hello,
Thank you for contacting Rank Math today.
Let me know if I understand you correctly, you wish to change your breadcrumbs from this “/category/dogs” to this “/dogs” If so, you can make sure the option to show categories in breadcrumbs settings is disabled: https://i.rankmath.com/0ovEMc
You can also use the following function.
/**
* this is an example to remove the second item in your post breadcrumbs
* 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 ) {
// 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);
Looking forward to helping you. Thank you.
-
This reply was modified 4 years, 3 months ago by Alberto.
No, no …Sir.. I don’t want to change the Breadcrumb, i just want to change the link in breadcrumb.
Example:
These are my breadcrumbs
Home > Dogs > Name
Everything its ok with these but if i clic on Dogs the link inserted is something like this mydomain/category/dogs.
I just want to change the link incrusted on DOGS in my breadcrumbs without the word category.
-
This reply was modified 4 years, 3 months ago by Pablo.
Hello,
I am we usually can’t provide custom code to our users due to we are a small team, the following is a sample code you can modify for this. Yu may have to hire a developer to assist you.
/**
*
* @param array $crumbs The crumbs array.
* @param Breadcrumbs $this Current breadcrumb object.
*/
add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
$ret = $crumbs;
$count = 0;
$modifiedCrumb = NULL;
$text_to_remove = 'Category Name';
foreach($crumbs as $crumb) {
if($crumb["0"]==$text_to_remove){
$modifiedCrumb = array(
"0"=>esc_html('PAGE NAME'),
"1"=>esc_url('/PAGE URL'),
"hide_in_scheme"=>false
);
break;
}
$count++;
}
if($modifiedCrumb!=NULL){
$ret[$count] = $modifiedCrumb;
}
return $ret;
}, 10, 2);
Looking forward to helping you. Thank you.
Hi,
This seems to solve a problem of mine as well. Where do I put this code?
Hans
Hello,
That code needs to go into your theme’s functions.php file.
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.