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?

2
  • 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?
    – avpaderno
    Commented Apr 8, 2011 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
    Commented Apr 8, 2011 at 13:43

1 Answer 1

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>?

2
  • 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
    Commented Apr 7, 2011 at 16:03
  • can someone with EDIT priviledges pleaes fix the highlight l('<li' . drupal_attributes
    – Alex Weber
    Commented Apr 7, 2011 at 17:26

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.