V
V
Vadim Timoshenko2015-02-19 17:33:09
Drupal
Vadim Timoshenko, 2015-02-19 17:33:09

How to add class to menu links programmatically?

The task is simple. It is necessary to programmatically add a couple of classes to the "menuname" menu links.
Add to all links without exception.
I could do it on jquery, but why if there is Drupal.
I searched in theme_menu_link, but there you can do everything only in a link wrapper,
but you need with the link itself.
I spent half a day on this nonsense, I have no more strength. save)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yakhnenko, 2015-02-19
@ayahnenko

function YOUR_MODULE_preprocess_menu_link(&$variables) {
  $variables['element']['#attributes']['class'][] = 'your_class';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question