I'm developing a site in drupal 7. I see that the function theme_menu_local_tasks() in includes/menu.inc is responsible for generating the secondary tabs. However the <li> elements do not have any IDs or classes. How do I start adding IDs and classes to the list elements?

1 Answer 1


The theme function that render the single menu local tasks is theme_menu_local_task(), which is the function that output the <li> tags.

return '<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n";

In a theme, you can implement an alternative of that theme function, using the code of that function as base; you then can add more CSS classes.

Supposing that your theme is "my_beautiful_theme," you need to create a "template.php" file (if it doesn't exist), and add the function my_beautiful_theme_menu_local_task() with the code for your theme function.

From a module is more complicated, but it has the pro of being applied for every theme you set in your site. If users are allowed to set a theme for themselves, you don't need to add that theme function in all the themes you enable, which also means not altering the code provided by other users. If you alter a theme you install, you then would lose your customizations every time the theme is update, and you install the update in your site.

With a module, you just need to implement something similar to the following code:

function mymodule_theme_registry_alter(&$theme_registry) {
  if (isset($theme_registry['menu_local_task'])) {
    $theme_registry['menu_local_task']['function'] = 'theme_mymodule_local_task'; // The new theme function.

function theme_mymodule_local_task(&$variables) {
  // Add here your code for the theme function.

For more information, you can look at hook_theme(), and hook_theme_registry_alter().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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