Archived topic
Remove product name from breadcrumb on Woocommerce product page
10 replies · Started by Neil on February 26, 2019
Hi,
On my Woocommerce product page I'm showing the breadcrumb above my product title. The breadcrumb includes the product title, which means that it is showing the product title twice, right next to one another.
Is there a way to remove the product title from the breadcrumb?
Thanks,
Neil.
Hi there,
The breadcrumb feature is actually coming from WooCommerce itself and GP doesn't have control over it.
I found this article on their documentation that might help:
https://docs.woocommerce.com/document/customise-the-woocommerce-breadcrumb/
If not then please check with their support.
Let me know if this helps :)
Thanks Leo, all sorted now.
If anyone else is looking to do the same, a really simple bit of code.
add_filter( 'woocommerce_get_breadcrumb', 'ed_change_breadcrumb' );
function ed_change_breadcrumb( $breadcrumb ) {
if(is_singular()){
array_pop($breadcrumb);
}
return $breadcrumb;
}
Awesome!
Thanks for reporting back :)
Hi,
This code removes product title but also removes link from category.
just fyi.
Is possible to remove product title without remove link from category??
Thanks
Hi there,
simplest method would be with some CSS. But if you want to remove the breadcrumb title entirely on the single post, then the PHP Snippet 2 referenced here can be used:
https://www.businessbloomer.com/woocommerce-rename-a-breadcrumb-item/
That code can be edited to replace the last crumb will null:
add_filter( 'woocommerce_get_breadcrumb', 'bbloomer_single_product_edit_prod_name_breadcrumbs', 9999, 2 );
function bbloomer_single_product_edit_prod_name_breadcrumbs( $crumbs, $breadcrumb ) {
if ( is_product() ) {
global $product;
$index = count( $crumbs ) - 1; // product name is always last item
$value = $crumbs[$index];
$crumbs[$index][0] = null;
}
return $crumbs;
}
then of course you have the Separators to deal with.
And Woo Provides this PHP Snippet to change them:
https://docs.woocommerce.com/document/customise-the-woocommerce-breadcrumb/#section-2
Which you can modify to also return null:
add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_delimiter' );
function wcc_change_breadcrumb_delimiter( $defaults ) {
// Change the breadcrumb delimeter from '/' to null
$defaults['delimiter'] = null;
return $defaults;
}
And then some CSS to add them back in after all crumbs except for the last one:
.woocommerce-breadcrumb a:not(:last-child):after {
content: '/';
margin: 0 5px;
}
Thanks, is possible to hide part of title, not entirely?
How do you mean 'part of title' ?
You can try this snipept:
add_filter( 'woocommerce_get_breadcrumb', 'bbloomer_single_product_edit_prod_name_breadcrumbs', 9999, 2 );
function bbloomer_single_product_edit_prod_name_breadcrumbs( $crumbs, $breadcrumb ) {
if ( is_product() ) {
global $product;
$index = count( $crumbs ) - 1; // product name is always last item
$value = $crumbs[$index];
$crumbs[$index][0] = substr($crumbs[$index][0], 0, 5);
}
return $crumbs;
}
In this line, $crumbs[$index][0] = substr($crumbs[$index][0], 0, 5);
the number 5 is the number of characters to display. Change that to suit.