Issue
I tried to remove the base shop tag from my breadcrumbs so that it should look like this:
Home / Category / Subcategory / Productname
instead of:
Home / Shop / Category / Subcategory / Productname
I found this solution on stackoverflow which helped a lot and removed the "shop" from the breadcrumbs
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;
}
Problem is that it now looks like that
Home / Category / SubcategoryProductname/.
Subcategory and Productname aren't separate by an / anymore and the / is at the end of the productname. Why is that? What is missing their to get the / between subcategory and productname?
Solution
Try to add the separator back in by using array_push. Note: you may need to change the forward slash " / " to match your separator.
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[0]);
array_push($crumbs," / ");
}
}
return $crumbs;
}
Answered By - codeKracken
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.