I'm using the built in menu manager to create my menues and I disaply them by using wp_nav_menu()
.
I'm wondering, is it possible to remove certain menu items from being displayed based on some specific condition?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI'm using the built in menu manager to create my menues and I disaply them by using wp_nav_menu()
.
I'm wondering, is it possible to remove certain menu items from being displayed based on some specific condition?
Use the wp_nav_menu_objects filter to adjust the menu items using whatever conditions you like. The filter will receive and return an array of the menu items.
unset($some_name_obj)
.
Instead of using wp_nav_menu()
, you can try using wp_get_nav_menu_items
which will return a list of menu items, then you can have conditional statements to pick an choose which to display.
http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items
walker
option. wordpress.org/support/topic/…
if our menu is pages you can use Exclude Pages from List
Just use the id of pages sepearated b comma
<ul>
<?php wp_list_pages('exclude=17,38' ); ?>
</ul>
UPDATE
Try this one
Go to Appearance -> Menu and then from there click "Create Menu" then add menus that you want to include and you can set a Location for menus with this code below try to explore
http://codex.wordpress.org/Function_Reference/wp_nav_menu
wp_nav_menu()
. I can't hardcode what pages are to be exluded in the menu, because it depends on some certain conditions.
wp_list_pages
without the include
parameter, will list all pages I have. That kind of defeats the purpose of having a custom menu. The whole point is selecting specific pages to be in the menu, by using the menu admin in WP. In order to list pages added through the menu admin, one must use wp_nav_menu
or wp_get_nav_menu_items
.