Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers 4

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.

share|improve this answer
    
I tested that earlier. But I was not able to remove the object from the array. I tested using unset($some_name_obj). –  Steven Aug 8 '11 at 15:04
    
You were probably unsetting it wrong. You have to unset it in the array itself to remove it from the array. Like unset($whatever['item']) then return $whatever. –  Otto Aug 8 '11 at 19:54
add comment

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

share|improve this answer
    
yeah, that might be a solution. Currently I'm using the walker option. wordpress.org/support/topic/… –  Steven Aug 8 '11 at 9:21
add comment

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
share|improve this answer
    
No. I'm managing my menu items from wp-admin and must use wp_nav_menu(). I can't hardcode what pages are to be exluded in the menu, because it depends on some certain conditions. –  Steven Aug 8 '11 at 9:18
    
try to my answer update I hope it helps –  idontknowhow Aug 8 '11 at 9:32
    
Using 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. –  Steven Aug 8 '11 at 10:22
add comment

Your Answer

 
discard

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.