Removing a static page from WordPress page list

Last updated on February 13, 2010. Tags: , ,

WordPress comes with a two kind of content page, static page (usually simply called "page") and post. While posts constitute the bulk of the content of the blog, pages are meant to be static and always accessible. Some of the pages that can be frequently found in WordPress-powered websites are the "About Us" page, "Contact" page, and if the site owner or administrator wants it, a static "Home" page.

This tweak was tested on WordPress 2.6.1 and 2.9.1. It will certainly work in all versions between these two and likely to work in nearby versions.

Whenever you add a new page, WordPress automatically creates a link in the navigation menu that is directed towards that page. Depending on the WordPress theme used, the navigation menu for the pages can be found at the header, at the sidebar or some other location in the page layout.

The PHP code that is responsible for listing all the pages in the navigation menu is shown below. It is usually located in the header.php or sidebar.php of a WordPress theme (depending on where you can find the page list).

<?php wp_list_pages('title_li'); ?>
Why would I want to remove some pages from the navigation menu?

There are cases wherein we need to create certain pages but do not want it to be accessible from the navigation menu. Some of these pages are the "thank you" page and "error" page; you want these pages to be accessible only through special conditions, such as your site visitor sending you a message.

Ok, so how to I hide certain page(s)?

To remove certain a page from the navigation menu, look at the page list and hover the mouse on the title of the page you wish to hide or remove to see its post ID. The post ID is the number at the end of the URL that appears in the status bar of your browser as shown in the screenshot on this post.

Let's say you found out that the post ID of the page you wish to hide is 11, simply add the condition exclude=11 between the parentheses of wp_list_pages as shown below. Simply replace 11 with the actual post ID of the page you wish to hide.

<?php wp_list_pages('exclude=11&title_li'); ?>

In most cases, there are already other conditions in the parentheses of wp_list_pages; in the example above, it's title_li. When you add the condition exclude=11, just place an ampersand sign (&) between the adjacent conditions as shown in the code above.

In some themes, the codes within the parentheses are much more complicated. The safest place to add exclude=11 without disrupting the other codes is either at the beginning right after the open parenthesis (must be followed by &) or at the end right before the close parenthesis (must be preceeded by &).

<?php wp_list_pages('exclude=11&title_li=<h2>Pages</h2>&sort_column=menu_order'); ?>

You can also remove from the page navigation menu two or more pages; just separate the page IDs with comma. In the sample code below, the pages with post IDs 11, 14 and 19 will not appear in the navigation menu.

<?php wp_list_pages('exclude=11,14,19&title_li=<h2>Pages</h2>&sort_column=menu_order'); ?>
Alternative: hide all but a few selected pages

As an alternative to excluding certain pages, you can also choose to show only a few pages by adding a code include=11,14,19 in the wp_list_pages as shown below; just replace 11, 14 and 19 with the post IDs of the actual pages you wish to show. You can have several pages as long as every two adjacent post IDs are separated by a comma.

<?php wp_list_pages('include=11,14,19&title_li=<h2>Pages</h2>&sort_column=menu_order'); ?>

When the wp_list_pages has an include code, it will display only the pages specified by the post IDs in the include code. When you created a new page, that page will not automatically appear in the navigation menu. You need to either specify its post ID in the include code, or remove the include code in its entirety.

Posted by Greten on July 20, 2009 under WordPress tweaks

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati

Related Posts

You might also be interested (randomly generated):

Read Comments

  1. Posted by bagas on 08.13.09 1:03 pm

    Many, many thanks! I’ve been trying to solve it by myself for hours…

    Cheers,
    Bagas

  2. Posted by Sasa on 01.29.10 10:19 pm

    Hi,

    I’ve been trying to do like you advised but my code is a bit different:

    where exactly should I put exclude=11&?

    Thank you very much for your help!

    Sasa

  3. Posted by Greten on 01.30.10 10:16 am

    @Bagas – you’re welcome.
    @Sasa – are you using WordPress? Please show me the exact code, the wp_list_pages() portion, and if there’s anything in the parentheses, kindly include them as well.

  4. Posted by Sasa on 02.01.10 10:08 am

    Hi, I’m sorry

    I’ve copied the code but didn’t paste it LOL

    Yes I’m using Wodpress the code is:

    Thanks again
    Sasa

  5. Posted by Sasa on 02.01.10 10:10 am

    Ok, it seems the problem is in the comments, because I can not sent you the code :( . Can I send you an email?
    Sasa

Post Comments

Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.





* Required. Your email will never be displayed in public.