Adding a span element in all menu items

Public

This code will add a span element in all menu items i.e
<a href="/contact">Contact</a>
will be
<a href="/contact"><span>Contact</span></a>

</> CopyGet raw version
php
  1. function yourthemename_menu_link(array $variables) {
  2. $element = $variables['element'];
  3. $sub_menu = '';
  4.  
  5. if ($element['#below']) {
  6. $sub_menu = drupal_render($element['#below']);
  7. }
  8. $element['#localized_options']['html'] = TRUE;
  9. $output = l('<span>' . $element['#title'] . '</span>', $element['#href'], $element['#localized_options']);
  10. return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
  11. }