Hi,
I wanted to Remove the tabs on some pages and Rename tabs on some pages. I searched for this and I found many posts related to this. But, They all were separate and I wanted to do both the tasks in one go. Though there are many posts are available to do these tasks I have modified the code to do this. Hence I would like to share this code with you all and would be very happy if it helps any one who is looking for the same. Below are the steps to do this -
1) To remove or rename the tab you will need to locate to the "template.php" file of your theme. You can locate to the template.php by following below path -
i) If you are using the default (i.e. garland) theme - /themes/garland( or your-theme)/template.php
ii) If you are using third party theme - /sites/all/themes/your-theme-name/template.php
2) Paste the below code at bottom of this file. Just keep in mind that you have to only paste the code within php short tags i.e. <? & ?>. Second important thing is replace the name "your-theme-name" with the name of your actual theme.
<?
function phptemplate_preprocess(&$variables, $hook) {
if($hook == 'page') {
your-theme-name_removetab('Create new account', $variables); // change "your-theme-name" with name of the them
your-theme-name_removetab('Log in', $variables);
your-theme-name_removetab('Request new password', $variables);
// Code to Rename the Tab on User account page
if(arg(0) == 'user')
{
your-theme-name_renametab('Edit', 'My Account', $variables);
}
}
return $variables;
}
// Function to rename the tabs
function your-theme-name_renametab($label, $replacement, &$vars)
{
$tabs = explode("\n", $vars['tabs']);
$vars['tabs'] = '';
foreach($tabs as $tab) {
$tab = str_replace($label,$replacement,$tab);
$vars['tabs'] .= $tab . "\n";
}
}
// function to remove the tab
function your-theme-name_removetab($label, &$vars) {
$tabs = explode("\n", $vars['tabs']);
$vars['tabs'] = '';
foreach($tabs as $tab) {
if(strpos($tab, '>' . $label . '<') === FALSE) {
$vars['tabs'] .= $tab . "\n";
}
}
}
?>
3) Save the file and check whether the changes are reflecting or not. In my case it has worked just in three steps. Hope this will help some one.
Comments
Thank you!
Thank you, vickyb, this was very useful tutorial. And what is the best - it didn't anyhow affected my website's performance. Before your solution I unsuccessfully tried to rename tabs with hook_menu_alter() found here #791684: Ability to modify views tab labels dynamically, but it crashed all submission/save forms on my website.
Very helpful!
Same here. Thanks very much vickyb for this wonderful tutorial. Worked like a charm!
Regards,
Saurabh