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!
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.
// Remove shop from breadcrumbs
function my_remove_shop_from_breadcrumbs( $trail ) {
unset( $trail['shop'] );
return $trail;
}
add_filter( 'wpex_breadcrumbs_trail', 'my_remove_shop_from_breadcrumbs', 20 );
add code in function.php
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 ' » ';
}
}
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/