Add a unique class for every menu item
Description
Adding a unique class for each menu item for the Drupal 7 themes, using the function in the template file. It may be necessary, for example, to the designation of each menu item to various color, etc.
Solution
Override function theme_menu_link(array $ variables) in your theme file. YOUR_THEME - is the name of your theme, and the class will be added for the li tag, and will look like - menu-[unique ID].
- $element = $variables['element'];
- $sub_menu = '';
- $element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];
- 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";
- }
Comments