8

i want to expand my theme's primary links, so I put the following code in my custom module.

function mymodulename_menu_link_alter(&$item, $menu) {
  if ($item['menu_name'] == 'primary-links') {
    $item['expanded'] = 1;
  }
}

In page.tpl.php I used print theme('links', $primary_links), but the primary links didn't expand. Why?

18

Not really a complete answer, but hook_menu_link_alter() is not called when the menu is rendered; it is called when the menu item is saved. Just an FYI.

2

Try after flushing the menu cache. For that, the Devel module will help you.

  • This is the real answer which deserves to marked as accepted. – Елин Й. Jan 7 '14 at 12:03
2

Start with simple things first. Use the Menu Example in the Examples Project. The menu_example_menu_link_alter() changes a link... You can use it there and experiment easily.

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.