Theming Drupal user login page

Since I didn't find a good tutorial for theming the Drupal login page I wrote one here. This is for the page if you want to theme the login block or login form take a look at http://drupal.org/node/350634.

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. To get the same template file to run on both you add in your template.php:

<?php function YOURTHEME_preprocess_page(&$vars) { // 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. array_unshift($vars['template_files'], 'page-login'); // Add body classes for easier css. $vars['body_classes'] .= ' userlogin'; } } ?>

Note you could add arg(1) == 'register' or 'password' to have it set on those pages as well. The last part adds a body class for our login page so that you in your theme can use for example: .userlogin a { color: green; }

That CSS will only be visible on the /user and /user/login for anonymous users. The body class .page-user that you will have as a default is also set on /user for authenticated users. 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.