What the best way to change css class for an active link from 'is-active' to (in my case) 'active'?

Also, need I really to replace it or to append my class? I know the 'is-active' class is hard-coded (here and in several php classes) and it is so strange for me since drupal is overloaded with many abstraction layers and tons of settings. What is it: "legacy of the past" or really well-founded idea?

I need 'active' class just for my current css-framework, but may be 'is-active' used in core or so?

Thank you!

  • I really believe that is 'well-founded idea', look in theme.inc file, function template_preprocess_links (api.drupal.org/api/drupal/core%21includes%21theme.inc/function/…). There is way to change this class changing just one file from core (for anon) and implementing a theme hook (for users). If you really get into, just ask.
    – Vagner
    Mar 7, 2016 at 13:10

1 Answer 1


You can override the theme_menu_link function like this:

function theme_menu_link($variables)
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = \Drupal::service('renderer')->renderRoot($element['#below']);

  foreach ($element['#attributes']['class'] as &$class) {
    if ($class == 'is-active') {
      $class = 'active';

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);

  return '<li' . new Attribute($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.