0

I know that using hook_menu_link I can add classes to the <li> tags but I need to add a class to the <a> tags within the <li> of a menu. I've looked and can't find a way.

Any ideas?

1

You can do it from hook_menu_link. You want to access the $vars['element']['#localized_options']['attributes']['class']

Something like this

$element = $vars['element'];
$element['#localized_options']['attributes']['class'][] = 'your-class';
$output = l($link_text, $element['#href'], $element['#localized_options']);

Then return the $output in the <li>. Be sure to account for $vars['element']['#below'] if you have a sub-menu.

  • Thank you, forgot to post that I found the same solution. – Ash Ahmadzadeh Jan 6 '15 at 20:26
  • Just a correction. It's a theme_menu_link not hook_menu_link. – jiv-e Mar 6 '15 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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