It is required to make the active menu item highlighted in the Drupal 7 theme. To do this, set the class to active <li> instead of <a> . For some reason, I can't change CSS. I theme_preprocess_menu_link() trying to do this with theme_preprocess_menu_link() :

 function mytheme_preprocess_menu_link (&$variables) { $element = $variables['element']; $attributes = $element['#attributes']; $attributes['class'] = array_unique($attributes['class']); $classes = $attributes['class']; if (in_array('active-trail', $classes) || ($element['#href'] == '<front>' && drupal_is_front_page())) { $element['#attributes']['class'][] = 'active'; } } function mytheme_menu_link__main_menu ($variables) { $element = $variables['element']; $sub_menu = ''; if ($element['#below']) { $sub_menu = drupal_render($element['#below']); } $output = l($element['#title'], $element['#href']); return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n"; } 

No result - as before, this class is set only for the a tag. Tell me, please, how to add a class correctly.

    1 answer 1

    The problem was solved by assigning $element links:

     $element = &$variables['element'];