Matt Danner
  • Blog
  • Contact
  • Twitter
  • Instagram
 November 13, 2009

Excluding Pages from WordPress Navigation

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

4 Comments
Categories : WordPress
Tags : Community, exclude, matt danner, navigation, night photography, php, WordPress
← Next Post
Previous Post →

Comments

  1. Diane Bourque says:
    February 2, 2010 at 10:18 pm

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

    Reply
  2. Matt says:
    February 3, 2010 at 3:19 pm

    Glad I could help!

    Reply
  3. Mark says:
    September 13, 2010 at 1:17 am

    Hi,

    This worked GREAT in one of my websites but a new one I started for my daughter I cannot find a single line of code that has part of that code in, in order to edit it.

    IF I just simply add the code then the page quits working and gives me an error on whatever line I put it in.

    Reply
    • Matt says:
      September 13, 2010 at 10:56 am

      Mark –

      What theme are you using on the new site?

      Also, this post is a bit out of date. With WordPress 3.0, you can do this with the built-in menu builder. It is VERY useful.

      -matt

      Reply

Leave a Reply to Matt Cancel reply

Your email address will not be published. Required fields are marked *

The Internet Home of Matt Danner Copyright © 2021
iThemes Builder by iThemes