I have a menu as such:

  • Home
  • Performances
  • News
  • Learning
  • ...

I have a content type called 'Event' and when viewing a node of the event type I want to set the 'Performances' menu item as active. How would I go about doing this?

menu_set_active_trail() doesn't seem to work :s


If you're using Drupal 7.9 or later you can use the menu_tree_set_path() function, e.g.

menu_tree_set_path('main-menu', 'performances');
  • I tried using this in template_preprocess_html() however this seems to be called too late to have any effect. Placing it in hook_init() did work, however is this the most appropriate place to put this logic?
    – Felix Eve
    Jun 2 '14 at 22:51
  • 1
    hook_init() doesn't fire for cached pages so YMMV there...better to do it in the context to which it belongs (in my opinion). So if 'performances' is a view, put it in a views hook, if it's a node a node view hook/preprocess, and so on
    – Clive
    Jun 3 '14 at 18:20
  • hook_node_view() is working great for me for my setup.
    – Felix Eve
    Jun 3 '14 at 22:57
  • template_preprocess_page() works fine for me.
    – user34185
    Apr 28 '15 at 12:51

Menu Position should do what you need (Drupal 7), it's fairly broad and contextual in scope. Once installed, go to /admin/structure/menu-position and add a new Menu Position rule. You will see there are all kinds of contexts, then theme away with Firebug and CSS (or you may not even need to depending on how your menus are already set up for active items / trails).

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.