1

Possible Duplicate:
How do I insert a <span> </span> tag inside the <a> </a> tag on my main menu

I tried the code found in How do I insert a <span> </span> tag inside the <a> </a> tag on my main menu, and I have a problem with it: while it does add the span tags, it also strips out the main menu's unordered list and classes.

How do I add the span tags inside the main menu links while also keeping the unordered list and the list menu classes?

  • Hello jive, and welcome on Drupal Answers. What is the difference between this question, and the other one? Did you read all the answers given for the other question? – kiamlaluno Apr 8 '11 at 3:35
  • @kiamlaluno . Yes I did read the answers. The difference is that the code provided (on both questions) strips out the main menu ul and li and the attribute classes. The output for the answer results in this and the output I'm looking for is this.(please also see my comment below) I guess my question should have been: How do I add the span tags inside the main menu links while also keeping the ul and the li tags and associated classes and not converting the opening and closing tags to gt and lt. – jive Apr 8 '11 at 13:43
1

Try this, http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links/7:

function THEMENAME_links__system_MENUNAME_menu($variables) {
  $output = '';
  foreach ($variables['links'] as $link) {
    $output .= l('<li' . drupal_attributes(array('class' => $class)) . '>' .'<span>'. check_plain($link['title']) .'</span>' . '</li>', $link['href'], $link);
  }
  return $output;
}

Is the <li> inside the <a>?

  • No, the <a> is supposed to be inside the <li> tag. However, the above code strips out the classed that drupal 7 gives for each menu item. The above code outputs this: link And the output I'm looking for is this:link. In your code, the assigned menu classes in the <li> tag (<li class="menu-501">) are missing. It also replaces any opening and closing html tag with &gt and &lt . @Westie @kiamlaluno – jive Apr 7 '11 at 16:03
  • can someone with EDIT priviledges pleaes fix the highlight l('<li' . drupal_attributes – Alex Weber Apr 7 '11 at 17:26

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.