Drupal 7 – Customize the user login block

In Drupal 7, there is a user login block. We can customize that block using the hook_form_FORM_ID_alter(). You can create a custom module or implement it directly in the theme template.php.

Here is a simple example written by Liam McDermott. You can add this in the template.php and replace THEMENAME by your theme name.

* Implements hook_form_FORM_ID_alter().
function THEMENAME_form_user_login_block_alter(&$form) {
  // For debug
  //drupal_set_message('<pre>' . check_plain(var_export($form, TRUE)) . '</pre>');

  // Remove the links provided by Drupal.

  // Set a weight for form actions so other elements can be placed
  // beneath them.
  $form['actions']['#weight'] = 5;

  // Shorter, inline request new password link.
  $form['actions']['request_password'] = array(
    '#markup' => l(t('Lost password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.')))),

  // New sign up link, with 'cuter' text.
  if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
    $form['signup'] = array(
      '#markup' => l(t('Register - it’s free!'), 'user/register', array('attributes' => array('class' => 'button', 'id' => 'create-new-account', 'title' => t('Create a new user account.')))),
      '#weight' => 10, 


Before you made any changes, i suggest you printing the $form array by uncommenting the the following line.

// For debug
drupal_set_message('<pre>' . check_plain(var_export($form, TRUE)) . '</pre>');


Then you can add or unset anything you want after knowing what is stored in $form array.

Done =)

Reference: aPaddedCell – Get more sign-ups from Drupal 7: make ‘Create new account’ eye catching

8 thoughts on “Drupal 7 – Customize the user login block”

Leave a Reply to ykyuen Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.