3

I need to create a page in my site that I am able to access via url, but that won't be included in any of the navigation menus which are generated using wp_list_pages() on my site.

How can I accomplish this?

  • Define menus?.. It can be pages widget, wp_list_pages function output, custom menu or something custom altogether. – Rarst Sep 24 '10 at 20:08
  • Ahh. Good clarifying question. I have edited my answer. I mean using wp_list_pages() – jessegavin Sep 24 '10 at 20:11
5

There is a good plugin that adds a meta check box under all pages that indicates whether you want the page to show up in menus.

Exclude Pages Plugin

The other option is to convert from wp_list_pages to the new custom menus. When using custom menus only pages you add to the menu will be included.

4

You're in luck, there's a filter. See this line inside wp_list_pages():

$r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );

So, just hook into wp_list_pages_excludes:

// add some new page ids to the exclude list
function my_banned_pages( $exclude_array ) {
    return array_merge( $exclude_array, array( 12, 45 ) ); 
}
add_filter( 'wp_list_pages_excludes', 'my_banned_pages' );
  • Works like a friggen charm! You rock! – jessegavin Sep 24 '10 at 20:31
  • I changed my accepted answer to the actual answer I ended up using. Your answer is "correct" though. – jessegavin Sep 25 '10 at 2:46
  • @jessegavin No sweat, glad you found a solution. :) – Annika Backstrom Sep 25 '10 at 23:25
0

just pass a flag to the wp_list_pages function call. All you need to do is get the page ID you want to exclude. See the example on the codex page listed below. http://codex.wordpress.org/Function_Reference/wp_list_pages#Exclude_Pages_from_List

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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