Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 758
Lotus Avatar asked Dec 01 '22 10:12

Lotus


2 Answers

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

like image 137
Suhail Avatar answered Dec 03 '22 23:12

Suhail


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 $crumbs;
}

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

like image 40
LoicTheAztec Avatar answered Dec 04 '22 00:12

LoicTheAztec