Drupal 7 – Customizing Main Menu Links
I spent a number of hours yesterday trying to figure out how to customize individual links for the main menu. Drupal 8 is a bit more straightforward, but it isn’t quite so obvious in Drupal 7. There are no template suggestions or theme hooks in the HTML comments when you turn theme debugging on, so it took me a while to figure it out.
Thankfully, with the help of PhpStorm and xdebug, I was able to pinpoint what template file to create:
Here’s my code that allows me to replicate the menu links exactly. Then customize as you wish.
<li class="<?php print implode(' ', $element['#attributes']['class']) ?>">
<?php print l($element['#title'], $element['#href'], $element['#localized_options']); ?>
<?php print drupal_render($element['#below']); ?>