Remove unwanted tabs from pages

Both Drupal core as well as various modules add tabs to pages that are not needed for general users, or not needed at all. You may wish to link to the page in a different way, as some users don't understand that they can click on the tab above a node.

Method for Drupal 4.7.x and Drupal 5

In versions of Drupal prior to 6, there was not a way to alter the hook_menu() generated tabs from code, so the function illustrated on this page will find and strip out a tab based on its name. As of Drupal 6, there is now the hook_menu_alter() function, which allows you to alter various properties of menu items that are set by core or other modules. If you are using Drupal 6, you should consider using hook_menu_alter instead, which is more exact, and is simpler/more efficient. One thing that hook_menu_alter cannot do that this page's method can is remove the "View" tab (if you have reason to remove the View tab, you can do so with this technique, and use hook_menu_alter for the rest of your tab removals).

Step 1 of 2

Locate your theme's template.php file. If one doesn't exist, create an empty one. This is where you can place customization PHP code.

Step 2 of 2

Custom functions placed in the themes template.php file should begin with the theme name. In the code snippet below replace "yourthemename" with the actual name of your theme, such as "garland".

You may already have a '_phptemplate_variables' function defined depending on what theme you are using, if so do not include the function again from the snippet below.

The tab removal work is done in the yourthemename_removetab() function, pass in a plain text tab label, along with the PHPTemplate variables, and the function will remove the tab.

In the above example snippet the 'address book' tab added by the eCommerce package is removed from the user's profile page.

Notes

Call yourthemename_removetab('tab name', $vars); for each tab you wish to remove.

No other modules need to be installed to use this.

If you need more exact control of which page on the site to affect (since different tabs might share the same name), you can wrap the removetab function with conditions that check the URL path arguments.

Method for Drupal 6

As mentioned in the introduction, generally you should consider using Drupal 6's hook_menu_alter to remove tabs instead. However if you need to use this page's tab removal method, the below code is adapted for use in Drupal 6. The notes and info in the above steps still apply in the same way.

First either add the first code snippet as shown, or else merge it with your current preprocess_page() function in template.php (you cannot have two of the same function, so look for preprocess_page). In both code snippets, change all instances of "yourthemename" to the name of your current theme, and do not include the opening and closing PHP tags.

After saving template.php, you may need to rebuild the theme registry before your changes will take effect. This can be done by clearing the cache at Administer > Site configuration > Performance, or through helper modules you likely have such as Admin Menu (top left icon) or Devel (in the Devel block).

Comments

This method works for me and is cleaner (IMO) and more performant than the regexp method:
Tabs are the default way of rendering menu items of type MENU_LOCAL_TASK or MENU_DEFAULT_LOCAL_TASK. So, there is a theming function theme_menu_local_task() in menu.inc that renders them. If you override it in your theme, you can skip certain tabs by simply returning the empty string as their rendered html:
This function would go into template.php in your theme.

I had a similar problem with drupal 6, and I couldn't get your fix to work.

What I did in stead was to add a new submit function to the search forms which makes a redirect to my custom search module (called 'userfinder') - heavily inspired by how the search module redirects to search/node.

This way the results of my own search module is presented first to the user. At first I wanted to remove the 'Content' and 'User' search tabs as well, and followed vijaythummar suggestion which worked perfectly. I ended up deciding to keep them as 'back-up' facilities though.

hey thanks this is just what i needed... only prob is on when using overlay i get this error "Notice: Undefined index: #primary in seven_removetab()" and the tab isn't removed... how would i fix that problem.

For some reason, if I try and remove the 'Content' tab on the Search page, the styling of the tabs gets messed up (there are no more tabs, just a real plain looking bulleted list!). I haven't investigated the code much yet, but looks like there is something special about the first tab in a series of tabs (other tabs that aren't first seem to get cut just fine).

You are correct, this method does not work any time it is the first tab, and thus this handbook method is poorly coded. What happens is the tabs get broken up by newlines, so as a basic example, tabs are the string: <ul><li>first item</li><li>second item</li></ul>

So if you delete the first tab item, it also deletes the first <ul>, so the list breaks! Hope this helps others, I'm sure there are good methods somewhere in the comments, I just haven't looked through all of them :)

Please note that the simple method for removing the User Search functionality is to disable the permission "access user profiles" for the role which you don't want seeing it. You may only be seeing this because you're logged in as an administrator.

I was trying to remove the 'Request new password' tab on the user login form and for some reason it wouldn't disappear until I realise that I needed to match the case of the text (capital R). Tada! It works!

I presume we have to change 'page' to a different content type if it applies. I changed youthemename to my theme name. With those changes (and removing the php tags) I could not get the "View" tab to go away..

I have different types of users. So i have different categories in profile. Now based on the user type I need to display certain tabs. Is there a easy way to do it or that i need to write a query to extract value from profile_values table and add the appropriate conditions in the proprocess funtion...

I needed this because I created a custom menu for different types of users, and created additional pages that start with /user/ in the url that I wanted any (if any) tabs to match. The menu I created is serving as the tabs in my particular case and has removed any confusion.

That works fine, and so does the method for Drupal 6 using menu_alter. The problem im having is I cant disable the functionality, only the tab.

For example. I have Node Gallery installed, I created an "Upload Images" tab, but of course it appears on all standard pages using MENU_LOCAL_TASK, not just the gallery pages. I can remove it easily enough using the above method for node type blog, page, story etc...but the user can still type in the direct URL and get the functionality - http://www.mydomain.com/node/22/upload...is a book node, without blocking actual functionality a user can upload images into book nodes, rather than the gallery itself!!! eeek.

I either need a way to make sure this tab only works with certain modules - in this case the node gallery module, or i need to block direct url access to the upload page on every other part of the site apart from the gallery...

It would be nice if the "user module" permissions group had an 'edit own account' checkbox, and have any module that wants to put a tab under My Account be required to put their own checkboxes here.

To be practical (since that suggestion isn't trivial), and since my site just disallows users to change email address or password, perhaps give us a way to hide certain widgets ("Account information" in my case).

I used this to remove the 'Edit' tab for the role 'customer' and disable access to the 'Edit' page altogether with the Path Access module.

I also have two roles, 'partner' and 'customer', with different Content Profiles, so I removed the 'partner' Content Profile tab when admin or editor are viewing a 'customer' role user, and vice versa.

Under Path access for the 'customer' role I added:

Access every page except the listed pages:
user
user/*/edit

To remove the 'Edit' tab for the 'customer' role only, and hide the "wrong" Content Profile from admin and editor:

I am not a php programmer and I've added this code below to remove the tabs but it's not working. I copied it to the end of the existing code. I've also tried it without both the at the beginning and the at the end. Can anyone tell me what I'm doing wrong please?

Why needing to do this at all to control the menu local tasks' tabs is beyond me. They are not accessible with Tab Tamer, Local Task Blocks or anything else I've found so far. I'd love to be able to keep some of the tabs but I can't do anything with them. I'm just so frustrated with them that now I just want them gone.

It is also possible to do this via hook_menu_local_tasks_alter(). Actually, that would be my recommendation over a preprocess_page call. This hook specifically handles the kind of menu modifications we're trying to accomplish on this page.

I modified the above to allow either removal or rename of multiple tabs. Just modify the $nodes array in the function. First dimension is content type name, second is key=path, value=renamed value. Leaving value blank removes the tab.

Simply naming the function properly will get it picked up by the theme registry on cache clear. The naming format is THEMENAME_menu_local_tasks. If you want to name it something else, then that's when you would use the relevant snippet for that above.