Remove a Drupal tab

Tagged:  

Have you ever been looking at a page on a Drupal site (like the login page) and wanted to remove a pesky tab (like the “Request a new password” tab), but could not figure out how to do it? Me neither, until recently. I went spelunking through the Drupal and theming core and uncovered some gems.

All the items that are to be tabs are specified as MENU_LOCAL_TASK in the specific hook_menu implementation. And there is a global way to intercept all theming for those types of items. You can them look them up, check their path(or any other piece of data) and decide whether or not to render it.

See below where I wanted to get rid of a tab with the URL user/password

function phptemplate_menu_local_task($mid, $active, $primary) {
    //Check each tab being rendered for our victim
    $item = menu_get_item($mid);
    if ($item['path'] == 'user/password') {
        return '';
    }

    //The rest is copied from theme_menu_local_task()
    if ($active) {
        return '<li class="active">'. menu_item_link($mid) ."</li>\n";
    }
    else {
        return '<li>'. menu_item_link($mid) ."</li>\n";
    }
}

Voila!

frank

Frank is a founder of Phase2 and the Chief Technology Strategist. He is intensely focused on making all this cool tech work hard for him.


Do you know how to make this work in Drupal 6? The code above doesn’t seem to work.

Roughly the same approach should work

http://api.drupal.org/api/function/theme_menu_local_task/6

But consider overriding it with [themename]_menu_local_task instead of phptemplate_menu_local_task. The theming system may have changed to not allow a global override like that.

I’ve found this same ‘fix’ on this page: http://drupal.org/node/68792 but I can’t seem to make it work! I am needing to remove the ‘search/node’ but it does nothing when I add it to my template.php file…

K, you have to replace ‘phptemplate_’ with whatever your theme name is…

That removed the tab, but only hid it. This still doesn’t solve my problem though : (

Back to the research grindstone!

What exactly is the problem you are trying to solve? Are you trying to not only hide the tab but remove that URL entirely from the system?

Funny how I can get LDAP authentication to work, but I still can’t get rid of that darn “Request new password” tab on the user login page…

Where do you put this fuction, and where is it called from?

TIA

You can either put the function in your theme, in the template.php file, or in any old module that you write. You can write a custom module just for this if you need to.