Customizing the "user account' title for register/login pages

Last modified: June 23, 2007 - 20:34

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.

Slight modification to test for user login

iosa - December 20, 2007 - 21:06

<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>

correction

eaposztrof - May 11, 2008 - 21:01

just a little correction:

- <?php elseif (arg(0) == 'user' &&  $user->uid == 0) : ?>
+ <?php elseif (arg(0) == 'user' &&  $user->uid === 0) : ?>

www.eaposztrof.com | www.iCode4Beer.com

Mind the profile pages

Jeroen Coumans - October 4, 2008 - 08:46

If your profile pages are public, than 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. Also note that I wrapped each text with the t() function to make it translatable with Drupal's localization module.

 
 

Drupal is a registered trademark of Dries Buytaert.