Last updated October 18, 2011. Created by sammos on November 29, 2006.
Edited by MGParisi, matijaerceg, DCCG, bekasu. Log in to edit this page.
description
Did you ever want to customize the "user account" title that appears at the top of the user/register, user/password, and user/login pages, to better describe the task the user is currently performing?
If you want to customise the full page layout, click through to the Customising the login, registration and request password full page layout handbook page.
In page.tpl.php, in place of:<h1 class="title"><?php print $title ?></h1>
Insert:
<h1 class="title">
<?php if (arg(0) == 'user' && arg(1) == 'register') : ?>
Create an Account
<?php elseif (arg(0) == 'user' && arg(1) == 'password') : ?>
Retrieve lost password
<?php elseif (arg(0) == 'user' && arg(1) == 'login') : ?>
User Login
<?php elseif (arg(0) == 'user') : ?>
User Account
<?php else : ?>
<?php print $title ?>
<?php endif ; ?>
</h1>And replace the text with whatever you wish. I'm sure there's a better way to write this code ;) but this works.
You can also do a small modification to test for user login:
<h1 class="title">
<?php if (arg(0) == 'user' && arg(1) == 'register') : ?>
Create an Account
<?php elseif (arg(0) == 'user' && arg(1) == 'password') : ?>
Retrieve lost password
<?php elseif (arg(0) == 'user' && arg(1) == 'login') : ?>
User Login
<?php elseif (arg(0) == 'user' && $user->uid === 0) : ?>
User Login
<?php elseif (arg(0) == 'user') : ?>
User Account
<?php else : ?>
<?php print $title ?>
<?php endif ; ?>
</h1>If your profile pages are public, these titles will override the account name with the text "User login." To account for that, use this code:
<?php
if (arg(0) == 'user' && arg(1) == 'register'):
print t('Create an account');
if (arg(0) == 'user' && arg(1) == 'password') :
print t('Retrieve lost password');
elseif (arg(0) == 'user' && arg(1) == 'login') :
print t('User login');
elseif (arg(0) == 'user' && arg(1) == '') :
print t('User login');
else:
print $title;
endif;
?>Note that only two == are required here. Also note that each text is wrapped with the t() function to make it translatable with Drupal's localization module.
Comments
Easier way
An potentially easier way is to affect the page.tpl.php via template.php. This code is the same as example #3. Place it in your template.php inside a hook_preprocess_page function. You may need to change the variable name ($var['title'] in the example below) to match your theme's title variable used in page.tpl.php.
// Customize the user login/register/password page titlesif (arg(0) == 'user' && arg(1) == 'register') {
$vars['title'] = t('Create a new account');
} elseif (arg(0) == 'user' && arg(1) == 'password') {
$vars['title'] = t('Retrieve lost password');
} elseif (arg(0) == 'user' && arg(1) == 'login') {
$vars['title'] = t('User login');
} elseif (arg(0) == 'user' && arg(1) == '') {
$vars['title'] = t('User login');
}
Yuck
Arg(0) and arg(1) are function calls, and you keep repeating them over and over again. Save them once at the beginning of the code and reference variables - much faster. Plus you can do the "user" check once and not have to do all those checks over and over. Or use a switch command.
<?php
// Customize the user login/register/password page titles
if (arg(0) == 'user') {
switch (arg(1)) {
case 'register':
$vars['title'] = t('Create a new account');
break;
case 'password':
$vars['title'] = t('Retrieve lost password');
break;
case '':
case 'login':
$vars['title'] = t('User login');
break;
}
}
?>
NancyDru
Can;t get it to work
Hi, would love to work out what is going on here. I have placed your php snippet into my template.php file under a function line "function theme350_preprocess_page(&$vars, $hook) {" Is this correct?
Nothing is changing. Thanks for your help
Works great -- anything for other title areas?
Thanks! I used this code snippet successfully. Is there a similarly easy way to change the page title in the other areas?
For example, /user still displays "User account" in the breadcrumb nav and the browser title area. Yuck.
How to change browser Page Title field for User Account page
I figured this out. Within page.tpl.php in place of:
<title><?php if (isset($head_title )) echo $head_title; ?></title>Add this:
<!-- This is a custom code used to rename the browser title bar for the user login page --><?php if (isset($head_title )): ?>
<title>
<?php if (arg(0) == 'user') : ?>
Custom Title Goes Here
<?php else : ?>
<?php print $title ?>
<?php endif ; ?>
</title>
<?php endif; ?>
To customise the title properly
You could put the following into a module, for example in the hook_init function (I expect there is a better hook to use but this one works for me):
<?php// Customize the user login/register/password page titles
// Strings match the page titles as set in user_menu() so they are translated
if (arg(0) == 'user' && arg(1) == 'register') {
drupal_set_title(t('Create new account'));
} elseif (arg(0) == 'user' && arg(1) == 'password') {
drupal_set_title(t('Request new password'));
} elseif (arg(0) == 'user' && arg(1) == 'login') {
drupal_set_title(t('Log in'));
} elseif (arg(0) == 'user' && arg(1) == '') {
drupal_set_title(t('Log in'));
}
?>
It means the browser page title, breadcrumb (if set to show the title of current page), and page title all get updated.
Andy
String Overrides
For those who prefer a UI approach, the String Overrides module provides a quick and easy way to replace any text on the site:
http://drupal.org/project/stringoverrides
String Overrides wont work
String Overrides wont work for this, as the string for all three pages is initially the same -- so overriding it with String Overrides will simply override it with a new string that will be repeated on all three "pages".
String Overrides is a great module though, just doesn't tackle this particular situation very well.
Hello, I tried the methods
Hello,
I tried the methods above and getting a weird result on multilingual sites using print t()
The title will first show in English then a slit second later it changes to its translated version. Why is that?
Is it possible to have the title show in the translated version immediately when the page loads?
Thank you
Hi all, All of us who were
Hi all,
All of us who were struggling for page titles, here is a great module which works efficiently
http://drupal.org/project/nodewords_pagetitle
Regards
Sagar
Need Drupal help?
Reach Me
Share your Posts, Url, Sites
www.sociopost.com
Worked perfectly, piece of
Worked perfectly, piece of cake first time.
The template file to be edited is obviously the one in the active theme folder for those who can't figure it out.
/public_html/user/sites/all/themes/active-theme
Strategic Websites Ltd
Website Design
Raised it as a core
Raised it as a core bug
#1251188: Fix page title for user/register, user/password, user/login pages, currently all the same
****Me and Drupal :)****
Clickbank IPN - Sell online or create a membership site with the largest affiliate network!
Review Critical - One of my sites