Remove navigation from header in custom page template

The question:

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.


The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

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') 

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.

Method 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);

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment