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.

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

There Are 7 Responses So Far. »

  1. 1 Jacob
    Wednesday, April 9th, 2008 at 2:28 pm

    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. 2 FreeBSD News
    Friday, June 27th, 2008 at 10:11 am

    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. 3 Big Fish
    Friday, July 4th, 2008 at 9:13 am

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

  4. 4 Mark B
    Wednesday, July 16th, 2008 at 7:41 pm

    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. 5 Kyle Eslick
    Wednesday, July 16th, 2008 at 8:27 pm

    @ 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!



Leave A Comment