Hide Pages from a Menu in WordPress 3.x

Written by Adrian Hart

Topics: Wordpress

If you have a page in WordPress you do not want to appear on a menu — for example, say you have created a static Home page, but don’t want it to be shown on the main menu, you can add an exclude argument in the menu function.

Find the function which calls your menu, the main menu function appears in the header.php file in the default TwentyTen theme. It looks something like this…

<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'menu_class' => 'main-menu', 'theme_location' => 'primary' ) ); ?>

To exclude a page from this menu you would add the following code to the array…

'exclude' => 'YOUR_HIDDEN_PAGE/POST_IDs'

Page and Post ID’s should be comma seperated. So now the menu function looks like this…

<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'menu_class' => 'main-menu', 'theme_location' => 'primary', 'exclude' => '6,12,18' ) ); ?>

To find your post or page ID, in your WordPress admin go to the post or page you want to hide, as if you were going to edit it. Look at the URL of that page in your browser. It will look like this…

http://your_domain.com/wp-admin/post.php?post=2&action=edit

Your Page or Post ID is highlighted in bold above. In this case the page ID is 2.

1 Comment Comments For This Post I'd Love to Hear Yours!

  1. Hello Adrain, In latest version of WordPress, there is no editing and we can hide the page from “menus” section

Leave a Comment Here's Your Chance to Be Heard!