How can I remove the "View" tab that appears next to the "Edit" tab? I am using the garland theme. No php I've tried so far has worked. I followed the instructions here to no avail:

http://drupal.org/node/68792

Is this a permission issue?? I do want people to be able to edit their posts.

Comments

dnewkerk’s picture

That code is not up to date for Drupal 6. Give this a try and let me know (works for me):

First either add this as shown, or else merge it with your current phptemplate_preprocess_page() function in template.php (you cannot have 2 of the same function, so look for preprocess_page. If you prefer you can use $hook like in the example you showed). This is a common function so with a lot of themes you'll have to merge it - just use the part betwen the { and } ....

function phptemplate_preprocess_page(&$variables, $hook) {
  // Remove undesired local task tabs
  mythemename_removetab('View', $variables);
  // End "Remove undesired local task tabs"
}

Then add this "outside" of phptemplate_preprocess_page() ... it should be on its own...

// Remove undesired local task tabs.
// Related to mythemename_removetab() in phptemplate_preprocess_page().
function mythemename_removetab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>' . $label . '<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}
// End "Remove undesired local task tabs"

In both code snippets, change "mythemename" to the name of your current theme.

It's nothing to do with permissions though, and also should not affect whether people can edit or not. One thing to watch out for is removing the View tab very well may break the theming of the local navigation tabs in some themes, so you'll have to troubleshoot that. In my case I'm using custom themed buttons rather than tabs so it wasn't an issue for me, but when I initially tested in another theme, the tab styling broke (removing other tabs didn't seem to affect it though, only the View tab... it's probably to do with any CSS relating to it being styled as the "first" tab).

Hope this helps. Let me know and I will update the handbook with the new example.

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

Ariesto’s picture

Great job outlining how to fix this Keyz! You were correct, my garland theme already had a preprocess function, so that heads up saved me one headache. The only change that I had to make was that my pre-existing prepocess function used '$vars' instead of '&$variables', so I just changed your "$variables" to "$vars".

Below is the exact outline of what worked for me with the garland theme. Thanks again!

function phptemplate_preprocess_page(&$vars) {
  $vars['tabs2'] = menu_secondary_local_tasks();

  // Hook into color.module
  if (module_exists('color')) {
    _color_page_alter($vars);
  }

// Remove undesired local task tabs
  garland_removetab('View', $vars);
  garland_removetab('What links here', $vars);

  // End "Remove undesired local task tabs"
} 


/**
*custom tab removal
*
*/

// Remove undesired local task tabs.
// Related to mythemename_removetab() in phptemplate_preprocess_page().
function garland_removetab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>' . $label . '<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}
// End "Remove undesired local task tabs"
scarer’s picture

I am trying to figure out how to re-name the Create new account tab.

Please help!

scarer’s picture

/* re-name Create new account tab to Subcribe */
function mytheme_preprocess(&$variables, $hook) {
if ($hook == 'page') {
if (arg(0) == 'user') {
$variables['tabs'] = str_replace('Create new account', 'Subscribe', $variables['tabs']);
}
return $variables;
}
}

Ariesto’s picture

thanks for posting your solution here, it should help out people with a similar problem.

mittalpatel’s picture

I wanted to remove Login and Request new password tabs from Registration page and achieved the functionality using your code.

I used
acquia_marina_removetab('Log in', $vars);
acquia_marina_removetab('Request new password',$vars);
acquia_marina_removetab('Create new account',$vars);
in phptemplate_preprocess_page function and it removed all the tabs :)

Is there any other way out to customize the registration and login page? (removing tabs and showing appropriate title)

gjmokcb’s picture

I could not get that puppy to work in a Zen sub-theme. Among other problems, the theme wasn't calling the preprocess function. I have no idea why. So I hard-coded the preprocess function into page.tpl.php (I know, you shouldn't have to), but the removetab function still wouldn't delete the tabs on the search page.

I tried with both phptemplate_preprocess_page and mytheme_preprocess_page.

I also tried it with and without this Garland-style line (adapted to Zen)

$vars['tabs'] = menu_secondary_local_tasks();

No luck. Ideas?

jruberto’s picture

In my experience, removing the first tab using the garland_removetab code messed up the html for rendering the local task tabs. (i'm using a zen sub-theme, that may be a factor) my guess is that important css classes/IDs are getting thrown out when removing the first menu item....

to fix, i just changed the weight of the first *remaining* tab so it is "lighter" than the view tab. i do not know what that actual weight of that first tab is, but -9999 seemed to be light enough. :-)

mrwendell’s picture

Suppose I wish to remove tabs from a custom module I create for the site. Do you know where I would look to hook into and change tabs? Any advice would be great.

The only way I know so far is by modify template files. I would like to avoid this as I think it should be done before that point.

Cheers!

mcfilms’s picture

So I guess I could also use this to remove the tabs like Outline, Track & Children. Right?

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

nickrice’s picture

If you don't want to get your hands dirty in code you might find that the Tab Tamer module (http://drupal.org/project/tabtamer) does what you want.