Last updated January 7, 2012. Created by Keyz on June 5, 2009.
Edited by steinmb, pcambra, jbrauer, ronald_istos. Log in to edit this page.
If you are using Drupal 6 or higher, a new hook is available called hook_menu_alter() which allows you to alter various properties of menu items that are set by core or other modules.
To use this function, you will need to make an extremely simple custom module to include the code snippet in, which the lesson How to create a simple Drupal 6 module in three easy steps should help with (or if you already have a custom module, simply add the function, adjust the name prefix, and clear the menu cache).
Do not include the opening and closing PHP tags, which are used here only to trigger code highlighting:
<?php
/**
* Implementation of hook_menu_alter().
* Remember to clear the menu cache after adding/editing this function.
*/
function MODULENAME_menu_alter(&$items) {
// Removing certain local navigation tabs that are either undesired or need to be custom relocated.
// Set these tabs to MENU_CALLBACK, so they still register the path, but just don't show the tab:
$items['node/%node/track']['type'] = MENU_CALLBACK;
$items['user/%user/track']['type'] = MENU_CALLBACK;
$items['search/user/%menu_tail']['type'] = MENU_CALLBACK;
// Fully unset these tabs and their paths, don't want them at all. This breaks the path as well:
unset($items['user/%user/example']);
}
?>After saving the code snippet in a custom module, clear the menu cache for it to take effect. This can be done by clearing the cache at Administer > Site configuration > Performance, or through helper modules such as Admin Menu (top left icon) or Devel (in the Devel block).
Note that using unset() on a menu item completely removes the path connected with that menu item (for instance, if the menu item being unset had a path of /user/example then that path would now provide a page not found error). Using the unset() method should only be used to completely remove menu items and their paths from a site.
This method should be able to remove most menu tabs, however it cannot remove the View tab. If you need to remove the View tab, you can do so using this alternate technique.
Comments
Possible to allow admin to view tabs?
This function works perfectly, but is it possible to hide some tabs for anonymous and registered users, while letting admin view everything and access their paths?
Thanks.
Hide user tabs, except for admin
With a lot of help (thanks!), I finally got it to work.
This function will hide the view, edit, and track user tabs, whereas admin, or user roles that are granted access, can see them. Follow the directions above to implement it in a module:
<?php
// $Id: remove_tabs.module
/**
* Set up a new permission for the module.
* Grant access under admin -> user management -> permissions
*/
function remove_tabs_perm() {
return array('view hidden tabs');
}
/**
* Implementation of hook_menu_alter().
* Remember to clear the menu cache after adding/editing this function.
*/
function remove_tabs_menu_alter(&$items) {
$items['node/%node/track']['access callback'] = 'user_access';
$items['node/%node/track']['access arguments'] = array('view hidden tabs');
$items['user/%user/view']['access callback'] = 'user_access';
$items['user/%user/view']['access arguments'] = array('view hidden tabs');
$items['user/%user/track']['access callback'] = 'user_access';
$items['user/%user/track']['access arguments'] = array('view hidden tabs');
$items['search/user']['access callback'] = 'user_access';
$items['search/user']['access arguments'] = array('view hidden tabs');
}
?>
To remove the personal contact form tab and form, use the x author module
I love this solution :)
I love this solution :)
This looks like exactly what
This looks like exactly what i am looking for, the only problem is i dont have a clue how to use it. I have created and enabled the custom module.
How do i make the view tab on a node invisible for example? I dont get how i target different tabs, if someone could explain this i would be very thankfull.
Regards
I have been using this and it
I have been using this and it is working awesome. I just tried using it for a sub-tab and it does not remove (hide or unset) the sub-tabs. What am I missing here? Thanks in advance!!
Hello, Is there any way
Hello,
Is there any way someone can grant access to the URLS rather than the tabs if a user is granted permission. I want to hide the tabs but I want to use the URLs in another menu I created in a primary menu block. T|he idea is to have users with correct granted permission to be able to modify their content. So far, I managed to get rid of the tabs. But when I do so, users are not granted access to the URLs even though the permissions are set correctly. It took some days to find out about it and it would be more than appreciated if someone could lead me in the right direction for this.
Thanks
T
Visit our Startups group on Drupal
Problem Solved! I got my
Problem Solved!
I got my inspiration from here http://drupal.org/node/604850
Phew!
Visit our Startups group on Drupal
possible to allow only registered user
it's possible to allow only register user?
Solution to disable the Track tabs
See this patch to add the needed permissions in the Tracker module to disable it:
http://drupal.org/node/762962
This patch has to be apply every time you update the tracker module. It's not as nice as an independent module, but it's much simple.
Unable to Unset Path to search/user
Using the example above I made a custom module to remove the Users tab from search pages. The tabs did disappear; however users are still able to access the search/user path and search for accounts.
Here is the code I used in the module. Did I miss something?
<?php
// $Id: custom_mod.module
/**
* @file
* Custom functions and overrides.
*/
/**
* Implementation of hook_menu_alter().
* Remember to clear the menu cache after adding/editing this function.
*/
function custom_mod_menu_alter(&$items) {
// Removing certain local navigation tabs that are either undesired or need to be custom relocated.
// Set these tabs to MENU_CALLBACK, so they still register the path, but just don't show the tab:
$items['node/%node/track']['type'] = MENU_CALLBACK;
$items['user/%user/track']['type'] = MENU_CALLBACK;
$items['search/user']['type'] = MENU_CALLBACK;
// Fully unset these tabs and their paths, don't want them at all. This breaks the path as well:
unset($items['search/user']['type']);
}
Maybe I'm wrong, but I think
Maybe I'm wrong, but I think you should use
unset($items['search/user']);instead of
unset($items['search/user']['type']);A slight modification
The following worked for me in Drupal 6 (in a module as described above) :
unset($items['search/user/%menu_tail']);how do you find the values
how do you find the values for all of the $items variables?
Free Chemistry Tutoring
%menu_tail also necessary for hiding
Using %menu_tail was the only way to reliably hide the search tabs. My function looks like this now:
<?phpfunction removetabs_menu_alter(&$items) {
$items['search/user/%menu_tail']['type'] = MENU_CALLBACK;
$items['search/node/%menu_tail']['type'] = MENU_CALLBACK;
$items['search/search_files_attachments/%menu_tail']['type'] = MENU_CALLBACK;
}
?>
I'll also experienced this,
I'll also experienced this, also had a quick look at http://api.drupal.org/api/drupal/modules--search--search.module/function... that also confirm this. I'll take my changes and change the documentation.
Stein Magne
http://smbjorklund.com
Tab Tamer module may do the trick
If you don't want to get your hands dirty in code you might find that the Tab Tamer module (http://drupal.org/project/tabtamer) does what you want.
print_r($items) inside of
@bjraines:
print_r($items) inside of hook_menu_alter, clear your menu cache and you'll get an array dump of all of them. View source in your browser to see them with nicer formatting.