I find myself wanting to control whether a menu item is shown on certain pages, much like how I can control how blocks are only visible on certain pages.

I cloned the menu using the Menu clone module, but have already experience maintenance issues and can only see it becoming more of a problem when the site goes live...

Is there a clever way of controlling menu item visibility?


I have done something along these lines with custom blocks. The basic approach is

  • Put everything you want in a menu, regardless of visibility
  • Make a custom block; make sure you don't cache it
  • In the render callback, get the menu $menu = menu_tree_all_data('menu-foo');
  • unset() any items in the $menu according to your visibility rules
  • Assign the items to $block['content']

Then you can assign the block to a region.

| improve this answer | |
  • Thank you @MPD By a custom block you mean a custom module, is that right? – kine456 Mar 1 '13 at 4:51
  • @kine456 Yes, custom block inside your own module. – mpdonadio Mar 1 '13 at 11:39

this module is worth a look: http://drupal.org/project/menu_item_visibility which allows for menu item filters similar to block filters (but alas no php filtering)

| improve this answer | |

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.