i got a user-login-block.tpl.php to customize user login block of Drupal 7. here is that code:

<div id='user-login-block-container'>
  <div id='user-login-block-form-fields'>
<?php print $name; // Display username field ?>
<?php print $pass; // Display Password field ?>
<?php print $submit; // Display submit button ?>
<?php print $rendered; // Display hidden elements (required for successful login) ?> 
  <div class='links'>
<a href='/user/register'>Create an Account</a> | <a href='/user/password'>Forgot Password</a>

this works; here is the screenshot:
enter image description here
but i want to print only the username field, password field and the submit button so i can easily position them, using css, adding custom label etc..
Also delete the blue marked default drupal 7 links.. any idea? thanks..

  • I don't understand what you are asking for. Do you need to remove links? Commented Jul 6, 2013 at 19:18
  • yes, and i also want to print every field individually. so this should render only the login field, pass. field and the button..
    – rakibtg
    Commented Jul 6, 2013 at 19:21

2 Answers 2


You need to define theme overriding for user login form via custom module.

 * Implements hook_theme().
function [modulename]_theme($existing, $type, $theme, $path) {
  return array(
    'user_login' => array(
      'render element' => 'form',
      'template' => 'user-login-form',
      'path' => drupal_get_path('module', '[modulename]') . '/theme',

function template_preprocess_user_login(&$variables) {
  $form = &$variables['form'];
  // So here you should define required variables
  $variables['name'] = $form['name'];
  // and so on ...

  unset($form['links']); // Removes links
  // don't forget $rendered variable.
  $variables['rendered'] = $form;

Then you should create template file for login form named user-login-form.tpl.php and put them into [modulename]/theme folder.

Don't forget use render() function to render form element's.

Hope, that what you are looking for.


In your theme's template.php file:

 * Implements hook_form_FORM_ID_alter().

function YOURTHEMENAME_form_user_login_block_alter(&$form) {



In this function you have access to the form as an array. Usually I enable devel module and do a dsm($form) . In your case dsm() will not work because you need to be logged in to be able to see the output. I used var_dump($form) to see the form and used unset() function to remove the links.

  • Thanks but i want to keep them! and want to delete the default links comes with drupal login block...
    – rakibtg
    Commented Jul 6, 2013 at 19:28
  • First of all, why you need this? If you removes links from standard output and split fields to independent variables, you "shoot yourself in the foot". There are many modules that modifies user login form, f.g. inserts new fields, create custom wrappers, and so on. You will have to manually (!!!) modify template each time something doesn't work as expected. ^^ Commented Jul 6, 2013 at 19:59

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.