wordpress - woocomerce - remove breadcrumbs from s

2020-04-17 07:03发布

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.

标签: php wordpress
1条回答
叼着烟拽天下
2楼-- · 2020-04-17 07:48

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);
}
查看更多
登录 后发表回答