We are having an issue where the "Show as expanded" checkbox is false whenever a new link is generated regardless of menu link weight.

Using the Superfish module we are displaying the menu block and tried to the following below to see if we can have the menu links expanded by default. However, during testing this is failing. We are using the latest Bootstrap theme as our base theme.

Test case:

1) Create a menu link for custom-menu
2) Navigate to admin page to view all the menu links
3) Click on edit on the menu link item
4) The Show as Expanded is disabled

Code (only hook in my .module file):

function mymodule_menu_link_alter(&$item, $menu) {
  if($item['menu'] == 'custom-menu')
    $item['expanded'] = 1;
  • Have you clear you cache? Sometimes, I will have to do it multiple time for the change to be visible
    – Emil Orol
    Aug 4, 2016 at 20:57
  • @redhatlab so i tried the following and it did not work. Before and after clearing cache: i updated the menu link from the node/edit screen by modifying the menu link title and weight. then i refreshed, but the "show as expanded" checkbox remained false. Aug 4, 2016 at 21:49
  • Theres a module called Menu Expanded which makes it really easy to set multiple links as "Show as Expanded". Useful, but not exactly what you're looking for!
    – Collins
    Aug 4, 2016 at 22:57
  • @Collins i have reviewed the module and all that changes is that it adds the "enabled" column up one level so with that module i wouldn't have to click edit and then enable the link. I would be able to do it without clicking edit. i am looking for a way to do set the show as expanded to true by default on edit/creation of a menu link item Aug 4, 2016 at 22:59
  • Have you seen drupal.org/node/685542 ?
    – Collins
    Aug 4, 2016 at 23:00

1 Answer 1


I tried your custom hook call, just to be sure it was called as you imagine, and to see how the $item array was build.

First, according to the hook_menu_link_alter() documentation, their is only one argument to this method in Drupal 7 (&$item).

And when I print the $item element, I can see that the name of the menu of the current element is not 'menu' but 'menu_name'.

Then your code must be something like :

function mymodule_menu_link_alter(&$item) {
  if($item['menu_name'] == 'custom-menu')
    $item['expanded'] = 1;

It is an interesting hook, because it is also called when a user add a menu directly from a node form options.

  • for some reason after clearing cache several times and making the edits you suggested, the expanded flag is still set to false. any other thoughts as what could be the issue? Aug 10, 2016 at 17:36
  • I just retested and now the menu link items are showing as expanded=true. Aug 10, 2016 at 18:35

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.