Add Menu Classes In Drupal 7

| Drupal Development | 44 seen

In this Drupal tutorial I'll show how to add menu classes to your Drupal 7 website using template.php file.

Original of this tutorial has been found here.

Add this function to your template.php file:

<?php
/**
* theme_menu_link()
*/
function THEMENAME_menu_link(array $variables) {
//add class for li
   $variables['element']['#attributes']['class'][] = 'menu-' . $variables['element']['#original_link']['mlid'];
//add class for a
   $variables['element']['#localized_options']['attributes']['class'][] = 'menu-' . $variables['element']['#original_link']['mlid'];
//dvm($variables['element']);
  return theme_menu_link($variables);
}
?>

P.S. If you are considering a hosting for your Drupal website check out Bluehost, their shared hosting starts as low as $3.95/mo or read more about cheap Drupal hosting.

 

Latest articles

Berlin Zoo and Aquarium: One of the Best Things To Do in Berlin With Kids

At the start of April 2026, during our roughly five-day trip to Berlin, we finally visited the famous Berlin Zoo for the first time - or at least the first time I can actually remember. There is a chance my mom might have taken me here sometime in the early 1990s, but if so, those memories are long gone. This visit felt completely new, and…

Germany |

Berlin Brandenburg Airport

In April 2026, I had my first experience with Berlin Brandenburg Airport (BER) while flying the Riga–Berlin–Riga route with airBaltic. This was my first time using Berlin’s main international airport, and overall, it left a solid impression—modern, functional, and relatively easy to navigate. About a decade ago, I had the chance to travel through…

Germany |