[Resolved] Remove product name from breadcrumb on Woocommerce product page

Home Forums Support [Resolved] Remove product name from breadcrumb on Woocommerce product page

Home Forums Support Remove product name from breadcrumb on Woocommerce product page

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #822560
    Neil

    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.

    #822719
    Leo
    Staff
    Customer Support

    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 ๐Ÿ™‚

    #823015
    Neil

    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;
    }
    #823485
    Leo
    Staff
    Customer Support

    Awesome!

    Thanks for reporting back ๐Ÿ™‚

    #1515606
    roadlink

    Hi,
    This code removes product title but also removes link from category.
    just fyi.

    #1922515
    Alfonso

    Is possible to remove product title without remove link from category??

    Thanks

    #1922707
    David
    Staff
    Customer Support

    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;
    }
    #1922790
    Alfonso

    Thanks, is possible to hide part of title, not entirely?

    #1922823
    David
    Staff
    Customer Support

    How do you mean ‘part of title’ ?

    #1922862
    Alfonso
    #1923178
    David
    Staff
    Customer Support

    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.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.