Community Documentation

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

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 titles
if (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;

    }
  }
?>

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

in the above function for D7

in the above function for D7 $vars should be $variables

This worked for me

Thanks, this is just what I needed.

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.

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

This is a 'hybrid' of your post and NancyDru's post that works great for me:

Edit your sites/all/themes/{YOUR THEME}/template.php

Find:
function {YOUR THEME}_preprocess_page(&$vars) {

Add this to function (right before last curly bracket if you are confused on where to place):

  if (arg(0) == 'user') {
    switch (arg(1)) {
      case 'register':
        drupal_set_title(t('New Accounts'));
        break;
      case 'password':
        drupal_set_title(t('Retrieve Password'));
        break;
      case '':
      case 'login':
        drupal_set_title(t('User login'));
        break;
    }
  }

This affects the following site url page titles (while logged out.):

/user/register
/user/password
/user

Since code above updates Title / "Real" Page Title (google) & Breadcrumb as you mentioned, it is also found by search engines as a unique page title.

Previously, these were all found/referenced by Google with a title of "Home |" (which is how I noticed the issue). Which makes sense because that was the real page title (not the 'drupal title', so the first few posts here do not help except with that).

Sample search result before fixing.

I see the latest patch passed testing per below. I hope it includes the real page title as well and finally fixes this issue. Maybe this was done by design(?), but for my site I like them unique. (not all named 'Home').

-b

This will also check the main

This will also check the main user account page and if the user isn't logged in, will change "User account" to "Log in".

<?php
 
if (arg(0) == 'user') {
    switch (
arg(1)) {
      case
NULL:
        if (!
user_is_logged_in()) drupal_set_title(t('Log in'));
        break;
      case
'register':
       
drupal_set_title(t('Register'));
        break;
      case
'password':
       
drupal_set_title(t('Request new password'));
        break;
      case
'login':
       
drupal_set_title(t('Log in'));
        break;
    }
  }
?>

Sudo bring me the remote. Drupal Web Design

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 help ?
Reach me on skype : sag_13684

Share your Posts, Url, Sites
www.sociopost.com

Need Varnish, Memcache, Apc, Solr, Drush and Drupal friendly host ?
http://drupion.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

Module or code snippet?

When you said piece of cake were you reffering to the module or the code snippet? Which route should I go down?

I created a module for this.

my module is called persons. I am using it from the buildamodule.com tutorial series.

this code will override your page title on the /user page
if you wanted to override the /user/login or user/register pages just adjust the $items['user/'] part of the code below.

function persons_menu_alter(&$items) {
//dpm($items);
$items['user']['title'] = 'Member Sign-In';
$items['user']['title callback'] = FALSE;
}

About this page

Drupal version
Drupal 4.7.x
Audience
Programmers

Archive

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here