Excluding Pages from WordPress Navigation

Posted by Matt on November 13, 2009 with 2 Comments

I have been fortunate to work with an awesome programmer who makes our WordPress themes incredibly easy to use. But recently, as I have been working with themes from other comanies, and one of the major problems I have run into is not having a Nav Builder. On almost every major site I have built for a client, there are pages that need to be linked internally, but not appear in the main navigation bar. Luckily, WordPress has made this really easy, and I just want to share the method I have been using.

First, I just want to post the basic call of the navigation. In the header.php file, call the nav using the following code:

<?php wp_list_pages(‘title_li=&depth=4&sort_column=menu_order); ?>

This code will list all pages.  Now I want to prevent certain pages from appearing in that list.  To do that, I need to find the IDs of the pages that I do not want to appear.  A simple trick to find the ID of the pages is to go to the Edit page under the Pages tab in the WordPress Dashboard.  Now I can simply hover over the page that I want to exclude, and use the link associated with that page to see its ID.

Now I need to use the page IDs in the code above to prevent them from showing up. To do this, add the &exclude command.  The above code will look like this after the change:

<?php wp_list_pages(‘title_li=&depth=4&sort_column=menu_order&exclude=PAGE IDs’); ?>

Replace “PAGE IDs” with the IDs of the pages you want to exclude.  It could look, for example like this:

<?php wp_list_pages(‘title_li=&depth=4&sort_column=menu_order&exclude=91,42,98′); ?>

This is a pretty basic change that anyone can easily make. Hope it helps.

-matt

Share and Enjoy:
  • StumbleUpon
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • Google Bookmarks
  • Print
  • email
  • RSS
  • Tumblr
Filed Under: WordPress

Get Updates via Email:


Don't miss a single post. Enter your email below to receive my latest blog post via email.


And... Follow me on Twitter.

Comments

  1. Thanks Matt – this is the code that I’ve been looking for all evening.
    It’s such a pleasure when we find it.

  2. Matt says:

    Glad I could help!

Leave a Reply