If you’ve downloaded a WordPress theme that has been made available to the general public, it is likely that, by default, it has some code that automatically inserts your WordPress pages directly into your theme without any manual coding.  This is a really great feature most of the time, but sometimes there are certain pages you’d like to not display in your menu or not display at all (search results page comes to mind).

Here is how the menu code probably looks in your theme:

<?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>

If you have a individual page you’ve created, but don’t want to display it in your blog’s menu, you simply need to add an exclude command and the page number (this can be found on Manage -> Pages) to your existing code. Here is how the same code would look if I was excluding page 55:

<?php wp_list_pages('depth=1&sort_column=menu_order&exclude=55&title_li=' . __('') . '' ); ?>

If you’d prefer to exclude more than one page, you can do so by simply adding a comma between each page number like so:

<?php wp_list_pages('depth=1&sort_column=menu_order&exclude=55,422&title_li=' . __('') . '' ); ?>

This code will exclude pages 55 and page 422 from your page menu.

Any other questions?  Feel free to post them below.

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!
Tweet This | Digg This | Stumble it | Add to Del.icio.us | | Print This

Kyle Eslick

Kyle Eslick is the founder and primary author of WordPress Hacks. You can learn more about him at KyleEslick.com or you can follow his personal tweets here.

There Are 9 Responses So Far »

  1. Jacob says:

    I know there is no built in feature for this request, but I am determined to find a way to exclude a category from wp_list_pages.

    From all the research so far I know that you can use a var, like:

    wp_list_pages(‘exclude=’ . $whatever);

    But I am not sure how to load that var with a list of page ids from a category.

    So basically I am asking if there is a way to return a list of page ids in a category. Any ideas anyone?

    Thanks in advance!

  2. FreeBSD News says:

    Thanks for this – it’s exactly what i’ve been looking for. I want to hide some pages from the top menu on my blog (otherwise it will look too busy there) and show instead all pages on the side.

    BTW, your sitemap isn’t working.

  3. Big Fish says:

    Thanks for this tweak! I just got rid of the poll archive from my menu.

  4. Mark B says:

    Is there a similar way to limit a search to only a few categories? I need to two different searches in a site…one of them should only echo results from a specific category. I would appreciate any help!!!

  5. Kyle Eslick says:

    @ Mark – Good question. The only thing that comes to mind is to use the WordPress default search engine, then also add a Google Custom Search Engine (GCSE) with the specified categories only.

    Not 100% sure that would work, but might be worth looking into!

  6. Why not just save the page as a draft? It hides the page from the menu, but you can link directly to it…

  7. Nellie says:

    There is actually a wordpress plug-in for all of this to hide the page(s).
    http://www.instinct.co.nz/hide-pages-plugin/

    http://wordpress.org/extend/plugins/wp-hide-post/

    Just in case one link doesn’t work the other should.

  8. lily says:

    thnx dude =) works perfectly by adding &exclude inside the parameter.

Trackbacks/Pingbacks »

Leave a Reply