I want to wrap my menu link titles in span tags. So I implement the theme_menu_link function in my template.php. However, that doesn't have any effect on menus displayed using Nice Menus. So I need to add a second function. I have to implement the special theme_nice_menus_menu_item_link function just to get the same functionality for my Nice Menus.

My template.php for my test theme ends up looking like this:

function test_menu_link($vars) {
  $vars['element']['#title'] = '<span>' . $vars['element']['#title'] . '</span>';
  $vars['element']['#localized_options']['html'] = TRUE;
  return theme_menu_link($vars);
}

function test_nice_menus_menu_item_link($vars) {
  $vars['element']['#title'] = '<span>' . $vars['element']['#title'] . '</span>';
  $vars['element']['#localized_options']['html'] = TRUE;
  return theme_nice_menus_menu_item_link($vars);
}

Nice Menus should instead work with the standard theme_menu_link function.

Comments

awasson’s picture

This looks like a syntax error in your code to me; the $vars argument should be (array $vars) not ($vars).

The code template you should be following is:

function THEMENAME_menu_link(array $vars) {
  $vars['element']['#title'] = '<span>' . $vars['element']['#title'] . '</span>';
  $vars['element']['#localized_options']['html'] = TRUE;
  return theme_menu_link($vars);
}
xiukun.zhou’s picture

Status: Active » Closed (fixed)
pratip.ghosh’s picture

Weird, why doesnt my version work?? I wrote something like this :

<?php
function seven_menu_link(array $variables) {echo '1111';exit;
}
?>

but the echo never gets executed when any page runs...

rashmit sidhu’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Make function in your custom module this will print your block name of your menu and replace '-' with '_'.

function MODULENAME_block_view_alter(&$data, $block) {
                print $block->delta . "<br/>";
}

Replace block name in your theme template.php describe below.

function THEMENAME_menu_link__BLOCKNAME(array $variables){
        $output = l($element['#title'], $element['#href'], $element['#localized_options']);
          return '<li' . drupal_attributes($element['#attributes']) . '>' . $output  . "</li>\n";
}

Let me know if you face any query/concern regarding this.

Thanks!

astonvictor’s picture

Status: Active » Closed (outdated)

I'm closing it because the issue was created a long time ago without any further steps.

if you still need it then raise a new one.
thanks