drupaldrupal-7drupal-themingdrupal-navigation

YOUR_THEMENAME_menu_tree__YOUR_MENUNAME not working


I have a custom Menu called "Footer", the machine readable name is "menu-footer". And I want override the theme_menu_tree() function for the menu. My theme name is "abc", so I tried abc_menu_tree__menu_footer() and it is not working. But modifying abc_menu_tree() is working, so it must have to do with the overriding of custom menus.

I checked this Question but it doesn't work. Is there anything I need to do in order to allow overriding for custom menus?

Thanks for your help in advance.

Edit:

The code of the function:

function abc_menu_tree__menu_footer($variables) {
  return '<nav class="sub-navigation"><ul>' . $variables['tree'] . '</ul></nav>';
}

abc_menu_link__menu_footer() can't be overridden too. In abc_menu_link() you are able to check context, so this is not a big problem. If I check if the theme of the element is "menu_link__menu_footer" it is working for the menu links.

Edit2:

I can't override abc_menu_tree for the main menu too. abc_menu_tree__main_menu is not working.


Solution

  • In order to use THEME_menu_tree on the primary menu, instead of using THEME_menu_tree__main_menu(), you will need to use THEME_menu_tree__primary()

    This is because the menu that provides the primary links is defined in admin/structure/menu/settings.

    I thought of this while digging around in the radix theme's radix_preprocess_page() function, wherein the main menu variable is set up for use in the page.tpl.php by using variable_get(). Duh! It's so easy to forget about those tiny little configurations.

    So yeah. THEME_menu_tree__primary() and THEME_menu_tree__secondary() are probably the functions you are looking for!