WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a simple function that adds a couple of pages to the users website when they activate my plugin. Actually there are many plugins out there that generate custom pages for the user, plugins like woocommerce do this.

Question: If the user does not have a menu assigned to their theme, many times the theme reverts back to simply showing a list of pages, I think by using the wp_list_pages() function.

Is there a way of automatically excluding my dynamically created pages from wp_list_pages()?

share|improve this question
up vote 1 down vote accepted

If you don't want them to ever be listed (using wp_list_pages at least) then you could hide them using a filter

add_filter('wp_list_pages_excludes', 'my_page_excludes');
function my_page_excludes() {
    // the array should contain the page ids you want to exclude
    return array(1,6,7,12);

This will stop them from displaying in anything that lists pages using WordPress template functions - including widgets etc. If the user may ever want them to be visible then they'd have to use a custom menu - or you'd have to provide an option to display them.

share|improve this answer
absolutely perfect! – shawn Jan 31 '13 at 5:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.