Hello,
Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.
In this case, you can use this filter to add the custom taxonomy in Rank Math 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 ) {
//Adding to single posts
if(is_product()){
//pass an array containing the name of the crumb, URL and
//hide_in_schema option
$value[] = array(
'PEPE JEANS',
'https://www.outletscarpeonline.it/jeans-flare/?brand=pepe-jeans',
'hide_in_schema' => false
);
//add this value as the second item in array
array_splice( $crumbs, 4, 0, $value );
return $crumbs;
}
return $crumbs;
}, 10, 2);
Here’s how you can add a filter/hook to your WordPress site:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Please also update the line in the code with the correct custom taxonomy URL as I’m unable to find it on your product.
Hope that helps.
Thank you.
ok is perfect! But i need to apply to 40.000 products!
i need to extract from my custom taxonomy “pwb-brand” the brand and add to all items.
With this function i will solve only 1 product
SOLVED!
/**
* 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 ) {
//Adding to single posts
if(is_product()){
global $product;
$terms = get_the_terms( get_the_ID(), ‘pwb-brand’ );
$titolo = $product->get_name();
if (!$terms) { echo ‘<h1>’.$titolo.'</h1>’; return; }
foreach ( $terms as $term ){
if ( $term->parent == 0 ) {
$brand_name= $term->slug;
$brand_title = ‘https://www.outletscarpeonline.it/brand/’.$brand_name.’/’;
}
}
//pass an array containing the name of the crumb, URL and
//hide_in_schema option
$value[] = array(
$brand_name,
$brand_title,
‘hide_in_schema’ => false
);
//add this value as the second item in array
array_splice( $crumbs, 5, 0, $value );
return $crumbs;
}
return $crumbs;
}, 10, 2);
Hello,
We are glad that it worked for you.
If you have any other concerns, please don’t hesitate to contact us anytime to assist you further.
Looking forward to helping you.
Thank you.