Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to add some classes to local task items, not there are only "active" class available which is pretty not flexible, I'd like to have "first" on first item and "last" on last item.

Tried theme_menu_local_tasks() and theme_menu_local_task(), both doesn't work. And this post is probably for Drupal 6 so it's not working either.

share|improve this question

You could use hook_menu_local_tasks_alter(). You can access all local tasks through the first parameter$data and you can add more class names to the option array localized_options of each tab.

function YOURMODULE_menu_local_tasks_alter(&$data, $router_item, $root_path){
        $tabs =  $data['tabs'][0];  
        $i = 1; 
        foreach($tabs['output'] as &$t){
            if($i == 1) $class = 'first';
            elseif($i = $tabs['count']) $class = 'last';
                $attributes = $t['#link']['localized_options']['attributes'];
                $attributes['class'][] = $class;
                $attributes = array(
                    'attributes' => array(
                        'class' => array($class)
            $t['#link']['localized_options'] = $attributes; 
        $data['tabs'][0] = $tabs;

If you don't want to loop through all local tasks for performance sake, you can directly update$data['tabs'][0]['output'][0] and $data['tabs'][0]['output'][$data['tabs'][0]['count']-1]. But you should check if the indexes exist, otherwise you will get Warning: Undefined index...

share|improve this answer

You may use the nth-child CSS 3 property if .active is not convinent:

p:nth-child(2) {

Source is MDN.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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