Skip to content

Instantly share code, notes, and snippets.

@dirtystylus
Last active December 25, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirtystylus/6992510 to your computer and use it in GitHub Desktop.
Save dirtystylus/6992510 to your computer and use it in GitHub Desktop.
Add Menu Title to LI elements.
/**
* Add unique class (mlid) to all menu items.
* with Menu title as class
*/
function THEME_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
$name_id = strtolower(strip_tags($element['#title']));
// remove colons and anything past colons
if (strpos($name_id, ':')) $name_id = substr ($name_id, 0, strpos($name_id, ':'));
//Preserve alphanumerics, everything else goes away
$pattern = '/[^a-z]+/ ';
$name_id = preg_replace($pattern, '', $name_id);
$element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'] . ' '.$name_id;
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";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment