Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home1/tylerfra/public_html/includes/common.inc).

Hide Local Task Menu Tabs in Drupal

Category: 

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.

Comments

Thanks it working fine...

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

function hook_menu_alter(&$menu) {
unset($menu['linkname']);
}

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! ;)