In Facebook Genesis group, a user asked:
I’m using Cafe Pro and I want to remove the menu from my WooCommerce pages only. I’ve looked through the functions file to try and find where it’s hooked in, but I don’t see it. Can someone point me in the right direction, please?
Primary nav menu (genesis_do_nav()
) is hooked to genesis_after_header
by default in Genesis.
add_action( 'genesis_after_header', 'genesis_do_nav' );
To remove this, we simply hook a function at a location which is one level above genesis_after_header
i.e., genesis_header
inside which we use the if condition to check for any/all WooCommerce page/s.
Add the following in child theme’s functions.php
:
add_action( 'genesis_header', 'sk_remove_primary_nav' );
/**
* Remove Primary Navigation Menu from all WooCommerce pages.
*/
function sk_remove_primary_nav() {
// if this is not a WooCommerce page or Cart Page or Checkout Page, abort.
if ( ! ( is_woocommerce() || is_cart() || is_checkout() ) ) {
return;
}
remove_action( 'genesis_after_header', 'genesis_do_nav' );
}
Remember:
Hook as late as possible.
Return as early as possible.
Reference: https://docs.woocommerce.com/document/conditional-tags/
This worked perfectly! Thank you, Sridhar. I even used it to figure out how to remove the utility bar above the header on the same pages. 🙂