Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

Hide Local Task Menu Tabs in Drupal


Here is how you can hide certain local task menu tabs in Drupal by utilizing theme_menu_local_task. The example below demonstrates how to hide the 'View' tab on user account profile pages. This code goes in your theme's template.php file.

function tf_menu_local_task ($link, $active = FALSE) {
  if (strpos($link,"/users/") !== false) { // we are on a user's page...
    if (strpos($link,">View<") !== false) { /* hide the 'view' tab */ return ''; }
  // default render
  return '<li ' . ($active ? 'class="active" ' : '') . '>' . $link . "</li>\n";

So, with this code we are actually preventing it from being rendered.


Thanks it working fine...

its also working... perfect way to use..

function hook_menu_alter(&$menu) {

tyler's picture

Thank you, your solution looks much more elegant!

A much better way would be to set the menu type to MENU_CALLBACK instead of unsetting the menu item completely:

  function yourmodule_menu_alter(&$items) {
    $items['linkname']['type'] = MENU_CALLBACK;

The advantage of that, the menu item and therefore the functionality of this menu item is still there, but there is no menu link for that path.

tyler's picture

My 2015 self definitely agrees with you on this! ;)

Add new comment