user10334265
user10334265

Reputation:

Remove "Shop" from Woocommerce breadcrumbs

I don't have a main shop page, only product categories. The Woocommerce breadcrumbs always show a "Shop" trail in the breadcrumbs which I need to remove. In the Woo docs I can only fibd info on how to change tthe "home" slug or delimiter, or how to remove the breadcrumbs entirely. How do I simply remove the "Shop" trail though?

EDIT: I do not want to alter/change the name/link of the "shop" trail but completely remove it!

Upvotes: 4

Views: 13918

Answers (5)

LoicTheAztec
LoicTheAztec

Reputation: 253804

Update (2024): Get the correct index in the crumbs array (thanks to @Sebastian)

To remove completely "Shop" from Woocommerce breadcrumbs, use the following:

add_filter( 'woocommerce_get_breadcrumb', 'remove_shop_crumb', 20, 2 );
function remove_shop_crumb( $crumbs, $breadcrumb ){
    foreach( $crumbs as $key => $crumb ){
        if( $crumb[0] === __('Shop', 'Woocommerce') ) {
            unset($crumbs[$key]);
        }
    }

    return array_values($crumbs);
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Upvotes: 7

Đi Outdoor
Đi Outdoor

Reputation: 29

this code worked for me It changes the JSON yoast seo

Last Tested: Yoast SEO 16.9 on WordPress 5.8

add_filter( 'wpseo_breadcrumb_links' ,'wpseo_remove_breadcrumb_link', 10 );

function wpseo_remove_breadcrumb_link( $links ){
    // Remove all breadcrumbs that have the text: Shop.
    $new_links = array_filter( $links, function ( $link ) { return $link['text'] !== 'Shop'; } );
 
    // Reset array keys.
    return array_values( $new_links );
}

Upvotes: 1

Suhail
Suhail

Reputation: 381

This worked for me, looks like woocommerce takes in consideration the index in the crumbs array.

add_filter('woocommerce_get_breadcrumb', 'remove_shop_crumb', 20, 2);
function remove_shop_crumb($crumbs, $breadcrumb)
{
    $new_crumbs = array();
    foreach ($crumbs as $key => $crumb) {
        if ($crumb[0] !== __('Shop', 'Woocommerce')) {
            $new_crumbs[] = $crumb;
        }
    }
    return $new_crumbs;
}

I hope this helps someone Thanks

Upvotes: 10

Pbinder
Pbinder

Reputation: 470

This snippet is more simple:

add_filter('woocommerce_get_breadcrumb', 'remove_breadcrumb_home');

function remove_breadcrumb_home( $breadcrumb )
{
    array_shift($breadcrumb);
    return $breadcrumb;
}

Upvotes: 1

Out of Orbit
Out of Orbit

Reputation: 563

For full control over the breadcrubs output I would recommend copying the file breadcrumb.php located in --> plugins/woocommerce/global/breadcrumb.php Put it at you-theme-folder/woocommerce/global/breadcrumb.php

My default breadcrumbs looked like this: "Home » Shop » Home » Category » Subcategory » Product" Home for some reason appeared twice. Below is the code from breadcrumb.php which shows how I removed the first apparence of "Home" and "Shop"

if ( ! empty( $breadcrumb ) ) {

echo $wrap_before;

foreach ( $breadcrumb as $key => $crumb ) {

    echo $before;

    //Every crumb have a $key which starts at 0 for the first crumb. 
    //Here I simply skip out of the loop for the first two crumbs. 
    //You can just echo the $key to see what number you need to remove. 
    if( $key === 0 || $key === 1 ){
        continue;
    }

    if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
        echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
    } else {
        echo esc_html( $crumb[0] );
    }

    echo $after;

    if ( sizeof( $breadcrumb ) !== $key + 1 ) {
        echo ' &raquo; ';
    }
}

echo $wrap_after;

}

To change urls, just set a new within the anchortag for a given $key or crumb[0] value. If you only whant this to happen at specific places in your store, just use woocommerce conditional functions such as:

if(is_product()){
    if( $key === 0 || $key === 1 ){
       continue;
    }
}

Only removes the two first crumbs if at a single product page. See more at https://docs.woocommerce.com/document/conditional-tags/

Upvotes: 1

Related Questions