Add a second custom taxonomy to breadcrumb

#575380
  • Resolved Anonymous
    Rank Math free

    Hi! I need to add a second custom taxonomy to my product breadcrumb

    this is a link example Pepe Jeans LEXA SKY HIGH Jeans Flare Donna

    This is current breadcrumb:

    HOME – DONNA – ABBIGLIAMENTO – JEANS FLARE – PEPE JEANS LEXA SKY HIGH JEANS FLARE DONNA

    what i need is to add the custom taxonomy “pwb-brand” in the breadcrumb to see something like

    HOME – DONNA – ABBIGLIAMENTO – JEANS FLARE – PEPE JEANS – PEPE JEANS LEXA SKY HIGH JEANS FLARE DONNA

    is there any hook to add in functions.php to do this operation?

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    Anonymous
    Rank Math free

    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

    Anonymous
    Rank Math free

    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/&#8217;.$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.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this ticket.