I am currently using theme_menu_link() but it themes every menu in Drupal. I only want to theme my main menu. How can I check for a specific menu?

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

//if(id == main_menu){ theme it different } 

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";

  • What do you need to do differently? And are you talking about the link elements themselves (the <li>) or the elclosing menu (the <ul>)?
    – mpdonadio
    Feb 5, 2013 at 17:38
  • yes,basically i want to add a div inside the <li>
    – bghouse
    Feb 5, 2013 at 17:39

1 Answer 1


You can get the ID of a menu by looking at the URL when you edit it in the menu configuration admin interface and converting dashes to underscores.

For example, on admin/structure/menu if I hover 'User Menu' I see admin/structure/menu/manage/user-menu/edit which means that the menu machine name is 'user_menu'.

The $element contains the menu's id: $element['#original_link']['menu_name'].

So you can put that in your if() and get

if($element['#original_link']['menu_name'] == 'user_menu') {

where you replace 'user_menu' with the name of the menu you want.

  • thanks this is what i wanted. but i forgot i am using Nice Menus Module. Do you know how I can theme these <li>'s instead?
    – bghouse
    Feb 5, 2013 at 18:35
  • I am not very familiar with that module. I think this would be a separate question.
    – beth
    Feb 5, 2013 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.