8

We want to rename the "Request new password" text on a Drupal's login page to some custom text.

In the user.module file, I see that this text is hard coded

if (variable_get('user_register', 1)) {
    $items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
  }
  $items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
  $form['links'] = array('#value' => theme('item_list', $items));

Is there any other way of renaming this text rather than modifying the Drupal core?

5

Have you tried the String Overrides module?

Provides a quick and easy way to replace any text on the site.

Features

  • Easily replace anything that's passed through t()
  • Locale support, allowing you to override strings in any language
  • Ability to import/export *.po files, for easy migration from the Locale module
  • Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
  • I tried solution below because I wanted to change the text for registering but it didn't work for me in D7. Didn't really want to install another module but I found String Overrides to be a great module and used it to change a bunch of strings. Awesome module! – John81 Jun 21 '12 at 2:02
12

The String Overrides module is a good suggestion if you have many strings, or need to constantly alter them, but you can also achieve this by editing the string overrides section of your settings.php file.

Simply uncomment the section so it looks like this:

$conf['locale_custom_strings_en'] = array(
  'Request new password' => 'MY CUSTOM TEXT FOR A NEW PASSWORD',
);
  • 2
    I like this solution better than installing a new module just for this one task! – Alex Weber Apr 1 '11 at 13:06
  • Never realised that this was an option before. It's a much nicer approach than installing yet another module. Unless of course you want to allow users to be able to define the new text from within the UI. – drmonkeyninja Jan 26 '12 at 9:46
  • 1
    Code above is for D6. For D7 use the additional empty bracket like so: $conf['locale_custom_strings_en'][''] = array() – Pooch Dec 12 '16 at 22:45
4

I just tried this in Drupal 7 but it wasn't quite right. It needs an extra [''] bit added. This works:

$conf['locale_custom_strings_en'][''] = array(
  'Request new password' => 'MY CUSTOM TEXT FOR A NEW PASSWORD',
);
1

I found two more ways of doing it:

Use your module name instead of 'mymodulename':

/*
 * Implements hook_menu_alter(). Change link text of 'Request new password' link.
 */
function mymodulename_menu_alter(&$items) {
      $items['user/password']['title'] = t('Reset password');
}
0

You can also do it in template.php of your theme, solution more flexible for my purpose (I wanted the text in French and English side by side):

/**
 * Implements hook_form_alter(&$form, &$form_state, $form_id)
 */
function YOURTHEME_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {
    //Modify the User Login Block Form
    case 'user_login_block':     
      $item = array(); 
      $items[] = l( t('Request new password') . ' |  <span class="en">' . t('Request new password', array(), array('langcode' => 'en')) . '</span>', 'user/password', array('html' => TRUE) ); 

      $form['links']['#markup'] = theme('item_list', array('items' => $items));

    break;
  }
} 

Originally inspired by Geoff Hankerson. Thanks to him.

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.