7 menu.inc theme_menu_tree($variables)
4.6 menu.inc theme_menu_tree($pid = 1)
4.7 menu.inc theme_menu_tree($pid = 1)
5 menu.inc theme_menu_tree($pid = 1)
6 menu.inc theme_menu_tree($tree)

Returns HTML for a wrapper for a menu sub-tree.


$variables: An associative array containing:

  • tree: An HTML string containing the tree's items.

See also


Related topics

4 string references to the theme hook from theme_menu_tree()

Note: this list is generated by looking for the string for this theme hook, so it may include some references that are not actually using this theme hook.

drupal_common_theme in includes/common.inc
Provides theme registration for themes across .inc files.
MenuTreeOutputTestCase::testMenuTreeData in modules/simpletest/tests/menu.test
Validate the generation of a proper menu tree output.
menu_reset_static_cache in includes/menu.inc
Resets the menu system static cache.
menu_tree_output in includes/menu.inc
Returns an output structure for rendering a menu tree.


includes/menu.inc, line 1612
API for the Drupal menu system.


function theme_menu_tree($variables) {
  return '<ul class="menu">' . $variables['tree'] . '</ul>';


I don't see it documented elsewhere that you can implement a THEMENAME_menu_tree__MENU_NAME() function as an override for a specific menu.

See http://drupal.org/node/254940#theme-suggestions-for-menus.

Just a note when implementing this in a sub-theme, you may need to use the base theme's name in your function name.

I bumped into this when implementing a bootstrap sub-theme.
MyTheme_menu_tree worked
MyTheme_menu_tree_my_menu didn't work
bootstrap_menu_tree_my_menu worked

Slight correction on this - you need two underscores before the menu name.

* Overrides theme_menu_tree().
* Add bootstrap 'navbar-nav' class to Top Navigation menu
function bootstrap_menu_tree__menu_top_navigation(&$variables) {
return '<ul class="menu nav navbar-nav">' . $variables['tree'] . '</ul>';

This function doesn't provide any context information like level or block id. This is a problem when you display the same menu in different block.

But you can use hook_block_view_alter to change the theme_wrapper.

I made a small example here https://gist.github.com/3201854

In case this is useful to anyone, I couldn't get it to work in html.tpl.php or page.tpl.php etc., but in template.php it worked fine.

How to add custom class to nested ul tag in drupal7?
I want to get my code as
<ul class="menu">
<li><a href="#">First</a>
<ul class="sub-menu">
<li><a href="#">one</a></i>
<li><a href="#">two</a></i>