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()?

1 Answer 1


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.

  • absolutely perfect!
    – shawn
    Jan 31, 2013 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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