I have the Sitemap module installed and it creates an unordered list of my chosen menu's items.

Main Menu looks like this:

Home - submenuitem1 - submenuitem2 - submenuitemn

Services - submenuitem1 - submenuitem2 - submenuitemn

References - submenuitem1 - submenuitem2 - submenuitemn

Links - submenuitem1 - submenuitem2 - submenuitemn

How can I add DIVs to each main menu item with its subitems ( Home+subemenuitems, Service+submenuitems etc.) ?

I managed to override site_map_menu_link to give it some depth at least.

function MYTHEME_site_map_menu_link(array $variables) {
    $element = $variables['element'];
    $sub_menu = '';

    $element['#attributes']['class'][] = 'menu-' . $element['#original_link']['plid'];
    $menu_id = 'menu-' . $element['#original_link']['plid'];
    $link_depth = 'depth-'. $element['#original_link']['depth'];

    if ($element['#below']) {
      $sub_menu = drupal_render($element['#below']);

    $output = l($element['#title'], $element['#href'], $element['#localized_options']);
    return '<div class="'.$menu_id." ".$link_depth.'"><li>' . $output . $sub_menu . "</li>\n</div>";

You can use theme_site_map_box in your template.php!

I've done something similar before where I've changed the H2's to H3's:

Try something like the following in your template.php

function MYTHEME_site_map_box($variables) {
  $title = $variables['title'];
  $content = $variables['content'];
  $attributes = $variables['attributes'];

  $output = '';
  if (!empty($title) || !empty($content)) {
    $output .= '<div' . drupal_attributes($attributes) . '>';
    if (!empty($title)) {
      $output .= '<h3 class="title">' . $title . '</h3>';
    if (!empty($content)) {
      $output .= '<div class="content"><div class="MYCLASS">' . $content . '</div></div>';
    $output .= '</div>';

  return $output;

I can't remember off the top of my head the structure of $content, but the above code should put an extra div around each section of the site map with the class of MYCLASS.

API Docs: theme_site_map_box()

  • Unfortunaly the code only put an extra div in between content div and the ul of the whole main menu, but not for each section of the main menu. – oll Dec 6 '12 at 23:45

Alternatively, you could use menu_block module to create blocks for each list. Then you can target them individually, mix in other content etc.

It provides configurable blocks of menu trees starting with any level of any menu. And more!


  • Hi Kim, menu_block is not an option for me, because we have an installation with the domain access module and lots of domains. with lots of menu blocks the administration gets real confusing. so we need a clean coded solution. – oll Dec 7 '12 at 9:20

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.