theme node tabs

Remove tabs using hook_menu_alter

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']['type'] = MENU_CALLBACK;

// Fully unset these tabs and their paths, don't want them at all. This breaks the path as well:

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

Syndicate content
 
 

Drupal is a registered trademark of Dries Buytaert.