wordpress - woocomerce - remove breadcrumbs from s

2020-04-17 06:54发布

问题:

I have wordpress with woocommerce. I am trying to stop the breadcrumbs displaying on the page that lists the categories which I have set as the 'shop page' in the wc settings.

The id of the page is '5' and it has the name/slug 'materials'

in my functions.php I have put

if (is_page('materials')){
    add_action( 'init', 'am_remove_wc_breadcrumbs' );
}
function am_remove_wc_breadcrumbs() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}

i have changed the selector in the if statement to 5 - no joy either. If I remove the if statement around the add_action then the breadcrumbs are removed from all the pages - as you'd expect.

回答1:

Give a try with following:

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);
}


标签: php wordpress