0

I am trying to change the heading in User Registration Page from User Account to Registration.

I tried pre-processing, but in the page variable title is empty and I can only see rendered html.

I also tried using the following code in the settings.php file, but it doesn't seem to work.

$conf['locale_custom_strings_en'][''] = array(
  'USER ACCOUNT' => 'Registration',
  'Add new comment' => 'post new comment',
);
4
  • 1
    Check this thread : drupal.org/node/100450
    – j2r
    Commented Dec 1, 2012 at 15:23
  • May you show the code you used to set $conf['locale_custom_strings_en']? As far as I know, it should work.
    – avpaderno
    Commented Dec 4, 2012 at 13:56
  • @j2r Hi, sorry for late response. Actually I had used arg(0) and arg(1) conditions and changed the headings but I was not sure if that would be standard method. After seeing the given link I feel the method used is acceptable. Commented Dec 7, 2012 at 11:37
  • @kiamlaluno the code is $conf['locale_custom_strings_en'][''] = array( 'USER ACCOUNT' => 'Something', 'Add new comment' => 'post new comment', ); Commented Dec 7, 2012 at 11:38

1 Answer 1

3

"User account" is the title that an anonymous user see for the "Create new account," "Log in," and "Request new password" pages. Replacing "User account" with "Registration" using $conf['locale_custom_strings_en'] would cause the string to be replaced in every place where "User account" is used, which is not correct.

screenshot

screenshot

The solution is to replace the title callback used for user with another title callback. Create a custom module, or add the following code to the custom module you are already using.

function mymodule_menu_alter(&$items) {
  if (isset($items['user'])) {
    $items['user']['title callback'] = 'mymodule_user_title';
  }
}

function mymodule_user_title() {
  if (!user_is_logged_in()) {
    switch (current_path()) {
      case 'user':
      case 'user/login':
        return t('Log in');
      case 'user/register':
        return t('Create new account');
      case 'user/password':
        return t('Request new password');
      default:
        return t('User account');
    }
  }
  else {
    return t('My account');
  }
}

The code I used for mymodule_user_title() is exactly the same code used by Drupal 8 in its user_menu_title().

Other solutions, such as using the String Overrides module don't work too, as they replace the string independently from the context, which is important in this case. Users who are in the page for requesting a new password should not read "Register" as title because they are not registering.

2
  • Thanks a lot. It works but when logged in, it is printing "username" while according the code it should "My account". Commented Dec 8, 2012 at 6:38
  • 1
    When you are logged in, and you visit example.com/user, you are redirected to http://example.com/user/<user id>. The title callback for that page is user_page_title(), and it has not been modified from my code.
    – avpaderno
    Commented Dec 8, 2012 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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