Remove a Drupal tab
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>";
}
else {
return '<li>'. menu_item_link($mid) ."</li>";
}
}Voila!




Comments
Funny how I can get LDAP
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 put it in 2 places
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.
So, did it work for you in
So, did it work for you in the end? I tried to follow these steps, but the tabs are still there. Have this issue in a few places, like the search page, where node and user modules insert unwanted tabs. The user pages have tabs that are hard to remove too.
Still works.
This has worked for me on a number of occasions. You can also get fancy and use hook_preprocess_page to modify the $tabs variable as a last resort.
To get rid of the Search Node and User tabs you can use the Core Search module. http://drupal.org/project/coresearches
Good luck,
Frank
Can't Make it work! :(
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…
Figured out the problem...
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 is the problem?
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?
How did you remove the tab?
I followed all the steps but my “Request new Password” tab is still there.
Do you know how to make
Do you know how to make this work in Drupal 6? The code above doesn’t seem to work.
Roughly the same should 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.
In D6 you will need to do
In D6 you will need to do smth like this in your template.php:
function mytheme_menu_item_link($link) {if($link['href'] == 'user/password') {
return '';
}
else {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
return l($link['title'], $link['href'], $link['localized_options']);
}
}
did'nt work for D6
Even this does not work in drupal 6!!
$link
That won’t work because $link contains HTML and is not an array. Here is how I got it to work on Drupal 6:
<?phpfunction yourtheme_menu_local_task($link, $active = false) {
if (strpos($link, 'The name of the tab I want to remove')) {
return '';
} else {
return '<li '. ($active ? 'class="active" ' : '') .'>'. $link ."</li>\n";
}
}
?>
Also, for both D5 & D6, make
Also, for both D5 & D6, make sure you clear your menu cache each time when testing.
Yes!
We can't forget the ritualistic clearing of the caches. Thanks. :)
I followed all the steps but
I followed all the steps but my “Request new Password” tab is still there.
Got it working for D6
Here's how I got it working for removing the Revisions tab - a bit clunky but you just search the end of the string
function YOURTHEME_menu_local_task($link, $active = FALSE) { if (substr($link, -13) == 'Revisions</a>') { return ''; } else { return '>li '. ($active ? 'class="active" ' : '') .'<'. $link ."</li>\n"; } }Oops, that should
Oops, that should read:
function YOURTHEME_menu_local_task($link, $active = FALSE) { if (substr($link, -13) == 'Revisions</a>') { return ''; } else { return '<li '. ($active ? 'class="active" ' : '') .'>'. $link ."</li>\n"; } }Sorry, can't for the life of me figure out how to put line breaks in this code...
hook_menu_alter
For D6, use http://api.drupal.org/api/function/hook_menu_alter.
Really? And how, pray tell, would you do that?
I think you should read the APIs before offering up a solution. This function does NOT provide what's needed to achieve the result described. It's for modifying menu data before it's saved into the database, not before it is rendered on the screen. Unless you want to completely remove the tabs from the entire system, this is not the way to do it.
chill out anonymous 'Really? And how...'
Take it easy, bro :) That was actually the answer I was looking for.
Post new comment