1

In D7, we need to modify the page title for the user login page (shown when users have not yet authenticated).

The default value is 'User account', and it is set in 'user.module' line 1965: return user_is_logged_in() ? t('My account') : t('User account');

It appears as the page title for the paths: user/register user/password user/login

This is how it is eventually rendered: User Account

To override the value for an authenticated user, we can simply implement

function MODULE_username_alter(&$name, $account) {
 $name = 'New Name!';
}

But how to override that value for unauthenticated users?

It seems like it should be done in THEME_preprocess, but I can't seem to find the attribute to set.

I implemented page--user--login.tpl.php, and see there that it is somehow part of $page['content'], but can't find the attribute to set.

0

You have alot of good information there (seriously). What you want to do is probably use hook_form_FORM_ID_alter() on the user form.

You want to set the #title attribute of the form element for the name element of the login form.

Some example code:

function MYMODULE_user_login_form_alter(&$form, &$form_state) {
  $form['name']['#title'] = 'Your Nickname:';
}

You'll probably want to check that a user is not logged in yet with something like user_is_logged_in() or your own custom logic.

  • I tried that (MYMODULE_user_login_form_alter) to no avail ... doesn't even get called in this context for some reason. The same module implements MYMODULE_form_alter, if which I set a block for $form_id = 'user_login', and that I can set attributes of the form, such as the text-edit captions for username and password, but the block-title "User account" is not available in this context... – August1914 Apr 10 '12 at 1:42
  • From the context of THEME_preprocess, I found that the text I'm targeting is set in $variables['head_title_array']['title'], (when $hook == 'html') and I can set it to my value, and trace it into core to see my value is there, but it is not rendered; overwritten downstream, I suppose? – August1914 Apr 10 '12 at 1:49
  • The function name in the example above is wrong. It should be: MYMODULE_form_user_login_alter – Jay Haase Aug 13 '15 at 0:24
0

I'm working on a group project, and somehow the title of my /user page was something completely unrelated to logging in. I thought I was going to have to create a module as described in the answer just to edit the page title, all the while I was bewildered at how someone in my group had managed to edit the page title without committing any code changes to the project.

I finally discovered that if you create a menu link in a menu to the path /user and you give the link a title, that title will be used as the page title for the login page. At least that's how it's working with the theme I'm using.

So, before you create an entire module to change your /user page's title, just try creating a menu link in any menu and giving that the title you want. Might save you some time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.