I have an 'audience' menu which has 4 links. When a user visits one of these links, it becomes active, and I want to push it to the front of the menu item list. Outcomes would like like;

Pitchers | Catchers | Hitters | Coaches
Coaches (active) | Pitchers | Catchers | Hitters
Catchers (active) | Pitchers | Hitters | Coaches
Hitters (active) | Pitchers | Catchers | Coaches

How can I accomplish this programmatically? I can't seem to find the right theme_ or hook_ api function to pull this off.

I've tried this, and changing the '#original_link' weight didn't seem to make a difference (note, I have other things going on here):

function apple_menu_link__menu_audience_gateway(&$vars) {
  $element = $vars['element'];
  $submenu = '';

  if($element['#original_link']['in_active_trail'] == TRUE) {
    $element['#original_link']['weight'] = 50;

  if ($element['#below']) {
    $submenu = '<ul class="nav">' . drupal_render($element['#below']) . '</ul>';

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);

  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $submenu . '</li>';

Also, I'm using Panels, Panels Everywhere, Page Manager, and MiniPanels — this could inform the ultimate solution.

Thanks all.

1 Answer 1


You need to use hook_menu_alter.

Make sure you declare the function with the & in front of items argument, this is what allows the function to modify the $items array passed to the function:

function MYMODULE_menu_alter(&$items)

In your function you can access every menu item in an array structure like so:

   $items['node/%/edit/schedulenew'] = array(
            'title' => 'Schedule1',
            'access callback'=>'user_access',
            'access arguments'=>array('view cssswitch'),
            'page callback' => 'cssswitch_schedule',
            'page arguments' => array(1),
            'type' => MENU_LOCAL_TASK,

If you just redefine the 'weight' property, it will allow you to re-order your menus.

  • Be sure to clear your cache after each menu changes, or go to the menu page, load the menu edit page and save it, this also rebuilds the menu.
  • 1
    I'm under the impression that hook_menu() and hook_menu_alter() are only invoked when Drupal rebuilds the menus. When a user visits one of the links it becomes 'active' and then I want it to reorder based on that interaction — not based on menu rebuilds. My post may not be clear enough: suggest an edit? Mar 6, 2015 at 21:38
  • Also, I'm using Panels Everywhere (& Page Manager, MiniPanels), which may alter the ultimate solution. Mar 6, 2015 at 21:43
  • I saw your edit. You would need js for this, it seems. There is possibly a module that does something similar you could check the code for inspiration. Mar 7, 2015 at 6:49
  • Thanks @stefgosselin. After 5 years of Drupaling, this is one of a handful of times Drupal hasn't had a straight-forward way of doing something. Maybe I'll package this into a module! Mar 7, 2015 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.