4

I am using Superfish menus. I wanted to add a <span> tag before each <a> tag for menu links. I tried the following code:

function mytheme_menu_link($variables) {
    $element = $variables['element'];
    $sub_menu = '';
    if (empty($element['localized_options'])) {
        $element['localized_options'] = array();
    }
    $element['localized_options']['html'] = TRUE; //let l function know that our link title includes html
    $output = l($element['#title'], $element['#href'], $element['#localized_options']);
    return '<li' . drupal_attributes($element['#attributes']) . '><span>' . $output . "</span></li>\n";
}

but it did not take any effect. Since I am using Superfish menus do I need to write any other code?

4
  • duplicate? Nov 25, 2011 at 12:58
  • Any update on this issue? I am having the same issue.
    – user6142
    Mar 13, 2012 at 11:05
  • - Nope dude. I could not find any solution.
    – Hacker
    Mar 13, 2012 at 12:29
  • @anonym-developer: nope, it's not a dupe, it's a totally different question, related to Superfish module's own menu rendering.
    – Sk8erPeter
    Aug 5, 2012 at 23:48

2 Answers 2

9

The Superfish module bypasses the usual Drupal theming hooks for menus and implements its own. You will need to override the theme_superfish() function in order to change the HTML around those menu items. Copy that function out of superfish.module into your theme's template.php file. Replace the word "theme" in the function name with your theme's machine name, and make your edits.

4

You can easily do this via the administration interface. You could also override theme_superfish_build(), but there's a simpler solution exactly for that task:

  1. Go to admin/structure/block, search for the given Superfish block, and click configure. E.g. in my test Drupal, I'll edit "Superfish 4" block (in my case the path is the following: admin/structure/block/manage/superfish/4/configure): Configuring Superfish block
  2. Scroll down to "Advanced HTML Settings", expand the fieldset, and below the "HTML Wrappers" sub-fieldset, there will be a field called "Around the hyperlinks" (NOT the "Around the hyperlinks contents"), type in the following:

    <span class="this-is-your-span-class">,</span>
    

    HTML Wrappers in Superfish

  3. Save block, and you're done.


Screenshots

BEFORE

Superfish menu - hyperlink without a '<span>' wrapper

AFTER

Superfish menu - hyperlink with a '<span>' wrapper

1
  • you rock man! you just rock! I didn't understand what to do with the comma, so I tried ,<span></span> which didn't have the desirable effect, and then stumbled upon your answer :) Jun 6, 2013 at 2:25

Your Answer

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

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