0

I want to turn off a the menu on certain pages in a genesis framework for WP. I have the following code:

function turn_off_menu() {
if (!is_front_page() || !is_page('blog')) {
remove_action( 'genesis_after_header','genesis_do_nav' ) ;
}
}

add_action( 'init', 'turn_off_menu');

But this is turning off the menu on every page.

rhysclay
  • 1,645
  • 3
  • 22
  • 42

1 Answers1

1

What pages do you want to exclude the menu on? You can do this with a page ID or slug.

How are your WordPress Settings => Reading configured as this will alter how you would do it.

Example:

 is_page( 42 );
 // When Page 42 (ID) is being displayed.

is_page( 'Contact' );
// When the Page with a post_title of "Contact" is being displayed.

is_page( 'about-me' );
// When the Page with a post_name (slug) of "about-me" is being displayed.

Your Code:

function turn_off_menu() {
 if ( !is_front_page() && !is_home() && !is_page('blog') ) { // Not default homepage or blog slug page

  remove_action( 'genesis_after_header','genesis_do_nav' ) ;
 }
}
add_action( 'init', 'turn_off_menu');

Ref: https://codex.wordpress.org/Function_Reference/is_page

wbdlc
  • 1,070
  • 1
  • 12
  • 34