Implement Menu block hook function hook_menu_block_tree_alter() to add/change/remove classes I have installed the plugin Menu block and I am very happy with the result, but I'd like to change some classes in the structure.

This is what I get right now:

&lt;div class="content"&gt;
    &lt;ul class="menu"&gt;
        &lt;li class="first last expanded"&gt;
            &lt;a class="active" href="http://example.com"&gt;News&lt;/a&gt;
            &lt;ul class="menu"&gt;
                &lt;li class="first last leaf"&gt;
                    &lt;a class="active" href="http://example.com"&gt;Test&lt;/a&gt;
                &lt;/li&gt;
            &lt;/ul&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;


..and this is what I want:

&lt;div class="content"&gt;
    &lt;ul id="nav-list"&gt;
        &lt;li class="first last expanded has-submenu"&gt;
            &lt;a class="active" href="http://example.com"&gt;News&lt;/a&gt;
            &lt;ul class="sub-menu"&gt;
                &lt;li class="first last leaf"&gt;
                    &lt;a class="active" href="http://example.com"&gt;Test&lt;/a&gt;
                &lt;/li&gt;
            &lt;/ul&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;


So I basically want to..


..add/change/remove the &lt;ul&gt;'s class and id attributes (level specific, so not the same for the primary/secondary &lt;ul&gt;).
..add a has-submenu class to an &lt;li&gt; if it contains another submenu.


What I've tried:

As explained in Menu Block's documentation, a hook function hook_menu_block_tree_alter() can be implemented. To start 'somewhere, I tried implementing this in template.php without any success (but doesn't even get called):

function THEME_menu_block_tree_alter(&amp;$tree, &amp;$config) {
  foreach ($tree as $key =&gt; &amp;$value) {
    if ($tree[$key]['link']['access'] &amp;&amp; !$tree[$key]['link']['hidden']) {
      $items[] = $tree[$key];
    }
  }

  $num_items = count($items);
  foreach ($items as $i =&gt; &amp;$data) {
    $class = array();

    if ($data['link']['has_children']) {
      $class[] = 'has-submenu';
    }
    $element['#attributes']['class'] = $class;
  }
}


Any help would be much appreciated as I don't really have deep understanding of how and where to implement this hook function. Also my impression is, that some more detailed documentation is missing for this specific hook function..
Other than the regular clear cache I am not sure why that would not be called. I do not have much experience with that hook. However I am fairly certain theme_menu_link would work here as well. Take a look at the answer here. A test for $vars['element']['#below'] should allow you to accomplish what you want.

Note: If you have a small menu you can always add classes to menu items through the UI.

EDIT: To answer part 1 try something like this (taken from bootstrap_menu_link):

if ($element['#below']) {
  if ((!empty($element['#original_link']['depth'])) &amp;&amp; ($element['#original_link']['depth'] == 1)) {
    // Add our own wrapper.
    unset($element['#below']['#theme_wrappers']);
    $sub_menu = '&lt;ul class="dropdown-menu"&gt;' . drupal_render($element['#below']) . '&lt;/ul&gt;';
    // Generate as standard dropdown.
    $element['#title'] .= ' &lt;span class="caret"&gt;&lt;/span&gt;';
    $element['#attributes']['class'][] = 'dropdown';
    $element['#localized_options']['html'] = TRUE;

    // Set dropdown trigger element to # to prevent inadvertant page loading
    // when a submenu link is clicked.
    $element['#localized_options']['attributes']['data-target'] = '#';
    $element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
    $element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
  }
}