简体   繁体   中英

Removing woocommerce breadcrumb from the shop, categories and tags page

I am trying to remove the breadcrumbs from my shop, category and tag pages. But nothing works.

add_filter( 'woocommerce_before_main_content', 'remove_breadcrumbs');
function remove_breadcrumbs() {
    if(!is_product()) {
        remove_action( 
'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
    }
}

Wanted to start from here but I don't know what is missing.

By CSS you can do like:

.woocommerce-page section#title {
  display: none;
}

Removing breadcrumbs with CSS is not the right solution, cause it still on the page (but hidden) and takes some time on page loading.

Find functions.php in your active theme folder and add this code at the end of the file:

// Remove breadcrumbs from shop & categories
add_filter( 'woocommerce_before_main_content', 'remove_breadcrumbs');
function remove_breadcrumbs() {
    if(!is_product()) {
        remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
    }
}

Using WooCommerce Conditional Tags we can build own logic. For example, code above is removing breadcrumbs on shop and categories pages, but leave it on the single product page.

You can remove breadcrumbs on the shop page, but leave it in categories:

// Remove breadcrumbs only from shop page
add_filter( 'woocommerce_before_main_content', 'remove_breadcrumbs');
function remove_breadcrumbs() {
    if(!is_product() && !is_product_category()) {
        remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
    }
}

Or you can also remove by page id or page slug:

add_action('template_redirect', 'remove_page_breadcrumbs' );
function remove_page_breadcrumbs(){
    if (is_page('YOUR_PAGE_ID_OR_SLUG'))
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM