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.

Frank Febbraro, Chief Technology Officer
#Development | Posted

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

  1. function phptemplate_menu_local_task($mid, $active, $primary) {
  2.      //Check each tab being rendered for our victim    
  3.      $item = menu_get_item($mid);
  4.      if ($item['path'] == 'user/password') {
  5.          return '';
  6.      }
  7.      //The rest is copied from theme_menu_local_task()
  8.      if ($active) {
  9.          return '<li class="active">'. menu_item_link($mid) ."</li>";
  10.      }
  11.      else {
  12.          return '<li>'. menu_item_link($mid) ."</li>";
  13.      }
  14. }

Voila!

Frank Febbraro

Frank Febbraro

Chief Technology Officer