Search code examples
drupaldrupal-7

How to add a span tag to a certain custom menu link in Drupal 7?


I'm trying to figure out how to add a span tag to a certain menu link in a custom menu. I only need it on one link within the custom menu links. Guessing a preprocess function and tried theme_menu_item_link() with no luck, didn't appear it was getting called at all.


Solution

  • Found the answer! Needed to use theme_menu_link():

    function theme_menu_link(array $variables) {
        $element = $variables['element'];
        $sub_menu = '';
    
        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";
    }
    

    http://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_link/7

    There I can find the item I'm looking for and adjust it accordingly.