Add a class to each of Drupal 7 primary tab items

Posted on: October 18th, 2013 by admin 2 Comments

If you find yourself wanting to style each tab individually, or attaching a certain JavaScript attributes to a particular tab this this code is very useful.

Just put this in your themes template.php.

function YOUR_THEME_NAME_menu_local_tasks(&$variables) {
	if (isset($variables['primary'])) {
		foreach($variables['primary'] as $menu_item_key => $menu_attributes) {
			$variables['primary'][$menu_item_key]['#link']['localized_options']['attributes']['class'][] = strtolower(str_replace(' ','-', $menu_attributes['#link']['title']));
		}
	}
	return theme_menu_local_tasks($variables);
}