Hello,

Is there a clean way to remove the view/edit tabs on a node page?

The only solution I could come up with so far is to add the following to the stylesheet:

.tabs {
  display: none;
}

But it's not perfect: it hides ALL node tabs on the site while I want to remove them only for CERTAIN node types.

Thanks,
Vincent

Comments

Michael M’s picture

Why do you want to hide the view and edit tabs?

Only users with permissions to edit the node will see the edit tab. Everyone else doesn't see anything because when there is only one tab, nothing is displayed.

----
http://PointHomes.com

vincentc’s picture

Only users with permissions to edit the node will see the edit tab. Everyone else doesn't see anything because when there is only one tab, nothing is displayed.

Thanks, but I know that. And precisely, I'd like users with the appropriate permissions to view/edit a node not to see the view/edit tabs.

Why? Because I have a custom display (theme) for my node including the view/edit buttons, so I don't want the default tabs to show because 1) the buttons appear twice; 2) it "ruins" my layout ;)

Michael M’s picture

Ah, ok. If I were you, I would apply the styling of the new tabs to the existing li's.

If not, look at http://drupal.org/node/11811

You need to create a template.php file in your theme's folder. The function you will be replacing with the template.php file is theme_menu_local_tasks() in the menu.inc file.

The current function looks like this:

function theme_menu_local_tasks() {
  $output = '';

  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
  }
  if ($secondary = menu_secondary_local_tasks()) {
    $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
  }

  return $output;
}

If you want the current node type to be inserted into the tabs:


function phptemplate_menu_local_tasks() {
  $output = '';
  $node = new stdClass();
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
  }
  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class=\"tabs primary tabs_". $node->type ."\">\n". $primary ."</ul>\n";
  }
  if ($secondary = menu_secondary_local_tasks()) {
    $output .= "<ul class=\"tabs secondary tabs_". $node->type ."\">\n". $secondary ."</ul>\n";
  }

  return $output;
}

If you want not to return anything if it is a certain node type:


function phptemplate_menu_local_tasks() {
  $output = '';
  $node = new stdClass();
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
  }
  if (in_array($node->type, array('page', 'audio'))) {
    return;
  }
  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
  }
  if ($secondary = menu_secondary_local_tasks()) {
    $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
  }

  return $output;
}

Modify the array with 'page' and 'audio' to your desired node types.

This will place the node's type into the ul's class attribute. I hope this works (I just typed it straight) and helps.

----
http://PointHomes.com

vincentc’s picture

That's great, Michael. Overriding theme_menu_local_tasks() fits the bill perfectly!! I was not even aware of its existence... ;-)
Thanks a million for taking the time to respond.
Have a nice weekend,
Vincent

joshuajoshua’s picture

I see how using this works with all sorts of nodes, but how can I hide tabs on my user profile pages?


Many thanks for any suggestions. I am baffled. EDITED: ahh... found it- http://drupal.org/node/77781

urbanarpad’s picture

Well... two years later, the above works for removing tabs on a nodeprofile but not when you're using a usernode to display nodeprofile info.

So, in order for that to work (i.e. when your URL looks like 'user/XX' not 'node/XX'), remember to change the line:

FROM:

 if (arg(0) == 'node' && is_numeric(arg(1))) {

TO:

 if (arg(0) == 'user' && is_numeric(arg(1))) {

I don't know how this: http://agaricdesign.com/note/removing-view-tab-from-embedded-profiles-us... actually works. I don't think it does.

rightchoice2c_me’s picture

what you can do is, you can create a seperate tpl file for user profiles there you can remove tabs.
just copy the same page.tpl.php and rename it to page-user.tpl.php and comment "print $tabs", it will not show tabs on user profile page.

Work Hard to understand what you have to do b4 U start, You may not be able to develop every detail but the more U know the less risk you take.