logo

Palette - Make it Colorful🎨

Palette - Visual Page Builder, no design degree required.

Live Demo Download Palette

Scroll

Menu theming (template.php)

29/07/2025, by Ivan
Forums

Hello, I insert the following code into the template.php file:

function your_theme_name_menu_link__main_menu(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }

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

But the <span> tag does not appear.

function your_theme_name_links__system_main_menu(&$vars) {
  foreach ($vars['links'] as &$link) {
    $link['title'] = '<span>' . $link['title'] . '</span>';
    $link['html'] = TRUE;
  }
  return theme_links($vars);
}

This construction works, but the wrapper is not where it should be — inside the <a><span></span></a> tag.

Please tell me what is the reason the first construction does not work?