WordPress Plugin Tutorial: Exclude Pages
When using WordPress as a CMS, sometimes you have to trick out page menu bars. I often run sites with many static pages that I don’t want showing up in menus or (especially) in the commonly used horizontal page menu bar. And I don’t want to make them all child pages of something. That would be weird.
Thankfully, as with almost everything in WordPress, as soon as I realized I had a problem, I was able to find someone who had already solved it for me. The Exclude Pages Plugin by Simon Wheatley adds a convenient little checkbox to the Page Edit page, asking if you want to include this page in page menus.
Fantastic.
Changing the Default Setting on the Exclude Pages Plugin
Most of the time when I’m using this plugin, it’s because I have some particular small group of pages I want displayed in navigation menus. I want the default to be “DO NOT include this page.” This makes me (and my clients who like to add pages and pages and ruin my beautiful navigation bars) have to think less.
Unfortunately, the default setting for the Exclude Pages plugin is “YES, include this page.” I wanted to change that.
If you’re using the Exclude Pages Plugin, and want to make the default setting an unchecked box, go into the exclude_pages.php file. (I did this right from the Plugin Editor inside the WordPress admin area.) Find the function called “ep_this_page_included” and change the first “return true” to “return false.”
Here’s what it looks like in the code:
BEFORE:
function ep_this_page_included() { global $post_ID; // New post? Must be included then. if ( ! $post_ID ) return true; $excluded_ids = ep_get_excluded_ids(); // If there's no exclusion array, we can return true if ( empty($excluded_ids) ) return true; // Check if our page is in the exclusion array // The bang (!) reverses the polarity [1] of the boolean return ! in_array( $post_ID, $excluded_ids ); // fn1. (of the neutron flow, ahem) } |
AFTER:
function ep_this_page_included() { global $post_ID; // New post? Do NOT include! if ( ! $post_ID ) return false; $excluded_ids = ep_get_excluded_ids(); // If there's no exclusion array, we can return true if ( empty($excluded_ids) ) return true; // Check if our page is in the exclusion array // The bang (!) reverses the polarity [1] of the boolean return ! in_array( $post_ID, $excluded_ids ); // fn1. (of the neutron flow, ahem) } |
Now, new pages do not display in menus by default, but can easily be turned on in their Edit page if you want them to.

By the way-
I’d like to thank Simon (the plugin developer) for his ridiculously meticulous code commenting. I only have a vague understanding of PHP (I’m learning…), but I was able to find this pretty easily because of his excellent (and sometimes humorous) comments.
[...] Read this article: WordPress Plugin Tutorial – Exclude Pages Plugin Change Default … [...]
hi
i have a child page that i want to hide in the horizontal navigation, but NOT the side rigght navigation. i installed the plugin and it works great, but it DID remove the child page from my right hand nav. how can i exclude the child page from horizontal but keep in the sidebar nav?
thanks!
cass
To do that, you’d have to manually edit the theme at the place you want the abbreviated list to display.
Disable the plugin. Go into your template code and look for “wp_list_pages” or “wp_page_menu”.
In the parenthesis after the function call:
wp_list_pages(HERE)
You can insert arguments that will tell WP how to display your list (including what pages to display or exclude). This is all explained in detail, with examples, at:
http://codex.wordpress.org/Template_Tags/wp_list_pages
Thanks so much for sharing this tip! Perfect!!
Jason