0

I'm building a landing page and want to remove the navigation menu from the page. The navigation menu is in header.php which is of course in the page template. Is there a WordPress function I can use to remove the navigation menu from this specific page? I know I could do it with jQuery and do display:none for the nav menu but i'd like to do it server side before the page loads.

Thanks

2 Answers 2

3

Use a conditional tag:

Codex References:

Function Reference (is_page)

Function Reference (Conditional Tags)

You can specify the landing page by Page ID, Page Title or Page Slug.

Here is an example:

<?php if ( !is_page( 'landing-page' ) ) { 
  wp_nav_menu( array( 
    'show_home' => 'Home', 
    'container' => 'false', 
    'theme_location' => 'main') 
    ); 
  }
  endif;
  ?>

It excludes the page (in this case the page with the slug "landing-page") by placing the ! in front of is_page

No need for javascript, this should do the trick.

2

I just answered on a duplicate question, but another solution is to filter wp_nav_menu.

Conditional logic will probably work as long as you haven't messed around with the query object and forgot to reset it.

function wpa76334_filter_nav_menu($menu, $args){
    if( is_page_template('your-template.php')) $menu = null; //use your own conditions
    return $menu;
}
add_filter('wp_nav_menu','wpa76334_filter_nav_menu', 10, 2);

Your Answer

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

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