1

I tried to remove breadcrumbs from homepage because it looks really ugly, but i can't do this because conditionals don't work. *I took that from woocommerce docs

add_action( 'init', 'wcc_remove_woo_wc_breadcrumbs' );
function wcc_remove_woo_wc_breadcrumbs() {
    if ( is_home() || is_shop() || is_front_page() ) {
        remove_action( 'woo_main_before', 'woo_display_breadcrumbs', 10 );
    }
}

Line

 remove_action( 'woo_main_before', 'woo_display_breadcrumbs', 10 );

works correct, but unfortunatelly conditional tags don't. Do you have any ida on woocommerce shop page as homepage?

4
  • I guess this is your problem in the docs: "is_home() uses the global $wp_query WP_Query object. is_home() isn’t usable before the ‘parse_query’ action."
    – Rup
    Commented Dec 30, 2019 at 3:07
  • Is_home and is_front_page are both same i think you need to use only one just try one by one and check which one causing issue Also use wp_reset_query(); first Commented Dec 30, 2019 at 5:35
  • 1
    If the woo_main_before action is executed once per request, you can try change add_action( 'init', 'wcc_remove_woo_wc_breadcrumbs' ); to add_action( 'woo_main_before', 'wcc_remove_woo_wc_breadcrumbs', 9 );. Maybe this question will prove useful.
    – nmr
    Commented Dec 30, 2019 at 7:57
  • It works in general @nmr but not by condition :D
    – Kama
    Commented Dec 30, 2019 at 17:26

1 Answer 1

1

For is_front_page() and is_home() condition:

Important: Please note that these functions work only once WordPress is loaded such as on template files or specific action hooks. You can’t just dump these conditionals into functions.php and expect them to work.

2
  • so why did they suggest such solution in documentation?
    – Kama
    Commented Dec 30, 2019 at 17:26
  • In the question these are being called from the init hook. That's not too early, is it?
    – Rup
    Commented Mar 17, 2021 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.