Theming Drupal 7 user login page

Theming Drupal 7 user login page

Since I didn't find a good tutorial for theming the Drupal login page I wrote one here.

Getting a page template for the user login page should be as easy as copying your page.tpl.php file and renaming it to page--user-login.tpl.php. Problem is when I tested this It didn't run on /user but only on /user/login page. To get the same template file to run on both you must add to your template.php:

<?php 
function phptemplate_preprocess_page(&$vars, $hook) {
  // Check to see that the user is not logged in and that we're on the correct page.
  if ($vars['user']->uid == 0 && arg(0) == 'user' && (arg(1) == '' || arg(1) == 'login')) {
    // Add a custom template-file "page--login.tpl.php" for user login form
	$vars['theme_hook_suggestions'][] = 'page__login';
  }
}
?>

Now copy your page.tpl.php and rename it to page--login.tpl.php. Then flush all caches an you should be good to go to edit your page-login.tpl.php file without affecting other pages.