Kat

How to Exclude Pages from WordPress

Exclude Pages in WordPressThere may be times when you might want to exclude pages from WordPress – from the navigation menu, header, footer, or sidebar. By default WordPress will display all pages you create in any location where pages are displayed. There are a few different ways in which you can exclude pages from WordPress navigation, and that’s what we’ll talk about today.

Method #1: Exclude Pages from WordPress by Modifying Code

Before you modify your theme code, be sure to backup the file to be modified. Usually the code to be modified will be found in the header, footer, or sidebar. Locate the following code:

<?php wp_list_pages();?>

When the parentheses are empty as shown above, all pages will be displayed. However, you can selectively exclude pages in WordPress by specifying the page IDs within the parentheses, as shown in the following example:

<?php wp_list_pages('exclude=14,27' ); ?>

Notice that you have to use the ‘exclude’ condition and must also specify the IDs of those pages you wish to exclude. In this example, pages with the IDs of 14 and 27 will be excluded from the header, footer, or sidebar.If you’ve modified your permalink structure as I’ve suggested you do (see the post entitled The BEST Permlink Structure for WordPress), the page ID will not be displayed in the URL of the published page. But it can be easily seen when you’re in page edit mode.

To find the page ID, click on Pages in the left column of your WordPress admin panel, and click on the page name whose ID you’re looking for. The ID will be displayed within the URL in the address bar (look for ‘post=xx’, where xx is the page ID number). It will look something like this:

http://www.yoursite.com/wp-admin/page.php?action=edit&post=96

Save your modified file, and you’re good to go. Bear in mind, though, that if you change your theme, you’ll have to modify the same files in the new theme.

Method #2: Exclude Pages from WordPress with a Plugin

While modifying your PHP code as described above is pretty straightforward, I always choose not to mess with code if there’s an easier and equally effective alternative.  A very effective plugin to easily exclude pages from WordPress is the Exclude Pages plugin, readily available from the WordPress plugin repository.

Once installed and activated, this plugin will add a checkbox (to each page or post) entitled ‘include this page in menus’ , which is checked by default. To prevent the page or post from being displayed in the usual areas, uncheck the box and click the Update button (or the Publish button if not previously published).

You can also exclude pages from WordPress with the pageMash plugin, which allows you to perform other page management tasks as well.

Method #3: Exclude Pages from WordPress with an Enhanced Theme

This last method is one in which you have only indirect control. There are some themes whose design allows you to modify menu structures without touching any code. If your theme offers this option, you’ll likely find it under Appearance > Menus.

I can’t provide you with specific usage instructions for this, as the interface design would be theme-dependent. But it’s pretty intuitive, almost like the drag-and-drop widget area that you’ve gotten accustomed to seeing. Once again, the caution here is that changes you make to a theme will be lost if and when you change themes.  It would be wise to create a site backup so that changes can be easily restored if you change your mind.

For a terrific backup solution, keep an eye out for my upcoming review on the BackupBuddy backup/restore/migrate plugin.

 

Leave a Reply