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)
7 menu.inc theme_menu_tree($variables)

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


includes/menu.inc, line 1622
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>

How was the development? were you able to do it? Mind sharing how you did it?

Any idea how to add, for example, the class "navbar-nav" only to the parent ul menu inside main_menu. The above mentioned code wraps all ul's (ie. including the children) with the same class.

How can I print the Title of a Menu Only?