Search code examples
woocommercebreadcrumbsstorefront

WooCommerce: Removing breadcrumbs for single products not working


I want to remove the breadcrumbs for all pages except for the product categories and single products. Unfortunately my conditional statement does not work. Can someone tell me what I have been doing wrong?

I tried to echo some text through the conditional and it all worked fine. Also removing the breadcrumbs without any conditional works fine.

    add_action( 'init', 'wc_remove_storefront_breadcrumbs');
    function wc_remove_storefront_breadcrumbs() {
      if ( !is_product() || !is_product_category() ){
         remove_action( 'storefront_before_content', 'woocommerce_breadcrumb', 10 );
      }
    }

With this piece of code the breadcrumbs are just being displayed everywhere.


Solution

  • I changed the tag and the priority in the add_action and it works fine now.

    add_action( 'storefront_before_content', 'wc_remove_storefront_breadcrumbs', 0);
    function wc_remove_storefront_breadcrumbs() {
      if( !is_product() ) {
       remove_action( 'storefront_before_content', 'woocommerce_breadcrumb', 10 );
      }
    }