the_liberal_gun_club
Sophomore
Just Getting Started
Member Likes (0)
I am trying to exclude pages created by Directory from my navigational menu. I have the Exclude Pages plugin installed : http://wordpress.org/extend/plugins/exclude-pages/
It has always successfully removed pages in the past, but I am guessing that since these pages are created dynamically that its having trouble.
When I try to exclude the pages from the nav menu, Directory creates another page with the same name and allows it to be included in the nav menu. I can't have all of these links in my nav menu, any way to exclude them?
Thanks in advance for your help.

Responses (11)
DEV Diva (joined February 2012) Likes (0)
Hi @the_liberal_gun_club
Welcome to our Community!
Have you tried using the WordPress Custom Menu function? You will find it under WP Admin Dashboard » Appearance » Menus.
You can read more about how to add a custom menu here:
WordPress Menu User Guide
Let me know if this helps and resolves the matter for you.
Have a great day ahead!
Gina
Member (joined June 2012) Likes (0)
Thanks for your reply Gina. Unfortunately, the theme we are using does not support custom menus.
DEV Diva (joined February 2012) Likes (0)
Thank you @the_liberal_gun_club
That does complicate things a bit, I agree. In this case we would have to look into the plugin itself to see how we can avoid the Directory pages from showing on your menu. Let me ping the Developer @Arnold for his input.
Talk soon again!
Gina
Developer (joined January 2012) Likes (0)
Easiest wat would be to add this kind of code to your functions.php in your Theme directory.
What it does is set $args['excluded'] to a list of menu page ids to exclude.
5,7,12,45
whatever they are on your system.
Member (joined June 2012) Likes (0)
Thanks for your help, Arnold. This looks promising but I am obviously putting the page ids in the wrong place.
I tried several different ways of putting them in and got a variety of errors, but no excluded pages. This is what I put:
/**
* Hide some menu pages
*/
add_filter( 'wp_page_menu_args', 'hide_menu_pages', 99 );
function hide_menu_pages( $args ) {
$pages = (empty($args['exclude'])) ? '' : $args['exclude'];
$pages .= ',' . 1568, 1571;
$args['exclude'] = trim($pages,',');
return $args;
}
It returned an 'unexpected T_LNUMBER' error in the $pages.= line. I tried moving the pages around with these other options which didn't work either:
$pages .= ',' 1568, 1571 . ;
$pages .= '1568,1571' . ;
Clearly I don't know what I am doing :)
If you could show me where to put the page IDs I think we will be set. Thanks.
Member (joined June 2012) Likes (0)
Actually, the error I listed above is not the correct error given the script I posted. That script returns "syntax error, unexpected ',' in...."
I can't remember how I got the T_LNUMBER error, I tried many different combinations. Sorry about that.
Developer (joined January 2012) Likes (0)
You're working with a string, not numbers So it would be
$pages = ',' . '1568,1571';
Need th squote marks.
Member (joined June 2012) Likes (0)
Ahhh... thanks again for your help.
Ok, I have updated as per your instructions. The error goes away but it doesn't actually hide the pages. Just for completeness' sakes, this is the exact text I have. And I have double checked the page numbers to be sure they are indeed the correct ones. I have also added other pages to the list that are not controlled by the Directory plugin (static pages I created) and they are not hidden either.
/**
* Hide some menu pages
*/
add_filter( 'wp_page_menu_args', 'hide_menu_pages', 99 );
function hide_menu_pages( $args ) {
$pages = (empty($args['exclude'])) ? '' : $args['exclude'];
$pages = ',' . '1472,1473';
$args['exclude'] = trim($pages,',');
return $args;
}
----
I put the above text, exactly as it is, into my functions.php file.
Thanks again!
Developer (joined January 2012) Likes (0)
Well that's the standard in Wordpress. You've got it right. You might make sure the exclude plugin is disabled. It may be going around the usual filter.
It may be that your Theme doesn't follow the standards and if so there's not much you can do except trace out their code. Since they don't support custom menu which has been around a long time there's no telling what they do.
There's one other trick you could try. Put the page you don't want in the menu in the trash but do not permanently delete them. Then see how it works. If you permanently delete them they'll just get recreated. Leaving them in Trash should let them work but not appear in the menu,
Member (joined June 2012) Likes (0)
Thanks again. What I wound up doing was to make each of these pages a child of the main 'directory' page since I could use the Exclude pages plugin to hide that page. That seems to be an acceptable solution for now. Thanks for your help.
DEV Diva (joined February 2012) Likes (0)
@Arnold, thank you for your great support on this topic!
@the_liberal_gun_club, glad you got sorted, even with your own solution :) Let me know if you require any further assistance. Have a good day!
Gina
Become a member