Wordpress Snippet #2: Style the login page

September 10, 2009 | Published in: Wordpress & plugins | Tags: , , , , 17

snippet

The Wordress Snippets series of posts will give you some useful code snippets for use in your projects – just copy and paste (but try to understand how they work!).

This snippet will add a stylesheet to your login page so that you can style it fully, and also change the default Wordpress logo link (to wordpress.org) and title text to something of your choosing. Add it to functions.php in your template.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function custom_loginpage_logo_link($url)
{
     // Return a url; in this case the homepage url of wordpress
     return get_bloginfo('wpurl');
}
function custom_loginpage_logo_title($message)
{
     // Return title text for the logo to replace 'wordpress'; in this case, the blog name.
     return get_bloginfo('name');
}
function custom_loginpage_head()
{
     /* Add a stylesheet to the login page; add your styling in here, for example to change the logo use something like:
     #login h1 a {
          background:url(images/logo.jpg) no-repeat top;
     }
     */
     $stylesheet_uri = get_bloginfo('template_url')."/css/login.css";
     echo '<link rel="stylesheet" href="'.$stylesheet_uri.'" type="text/css" media="screen" />';
}
// Hook in
add_filter("login_headerurl","custom_loginpage_logo_link");
add_filter("login_headertitle","custom_loginpage_logo_title");
add_action("login_head","custom_loginpage_head");

How it works

We simply use the wordpress hooks on the login page (custom_loginpage_logo_link, custom_loginpage_logo_title, custom_loginpage_head) to insert our code and modify the existing title text and link to something of our own.

Found this post useful? Why not buy me a coffee!

Related Entries

17 Responses to “Wordpress Snippet #2: Style the login page”

RSS feed for comments on this post.

  1. John Nixon says:

    I just want to say you rock and I will be making donation(s). Please, keep up the good work. I am a fan.

    ReplyReply

    Comment made on September 21, 2009 at 5:51 pm

  2. Mike Jolley says:

    @John Nixon: Thanks, that’s nice to hear :)

    ReplyReply

    Comment made on September 21, 2009 at 10:00 pm

  3. David Zemens says:

    Great information Mike. I have made a custom graphic for my clients login page, but once they did an update to WordPress it was always overwritten. This snippet solves that problem. Thanks very much.

    ReplyReply

    Comment made on October 9, 2009 at 4:15 am

  4. araneum says:

    How you put image URL? Relative URL or full URL with http://www.

    I have to replace wordpress login logo under image folder at wp-admin directory with my logo for my logo to show up properly in login page.

    Thx

    ReplyReply

    Comment made on October 15, 2009 at 8:56 am

  5. Mike Jolley says:

    @araneum: Full url. If you follow the above instructions exactly it will work.

    ReplyReply

    Comment made on October 15, 2009 at 9:23 am

  6. Andy Fitzpatrick says:

    This is brilliant we were just discussing how to change this page many thanks

    ReplyReply

    Comment made on October 20, 2009 at 12:09 pm

  7. BigM75 says:

    very great things, nice artikle

    ReplyReply

    Comment made on December 22, 2009 at 1:02 am

  8. meme says:

    hi
    thanks for the code
    but i really have problem on making it work
    where exactly should i place the code, i tried put it on the function.php but that’s not working
    should i replace an exciting code with this or what
    pleeeease help me on this and tell more details , i really need it

    ReplyReply

    Comment made on December 25, 2009 at 12:45 pm

  9. Mike Jolley says:

    @meme: functions.php – plural.

    ReplyReply

    Comment made on December 28, 2009 at 6:55 pm

  10. gofree says:

    So we only need to modify this:
    // Hook in
    add_filter(“login_headerurl”,”custom_loginpage_logo_link”);
    add_filter(“login_headertitle”,”custom_loginpage_logo_title”);
    add_action(“login_head”,”custom_loginpage_head”);

    we put all code in between php?

    ReplyReply

    Comment made on December 29, 2009 at 10:54 am

  11. gofree says:

    Looking through, still can’t get a scope of modifying. Can you show sample modifying?

    It seems that not to modify the above code, but just copy and paste then create .css named it login.css in the template folder. Am I right?

    Again, please sample the css, plz.

    ReplyReply

    Comment made on December 29, 2009 at 11:11 am

  12. Mike Jolley says:

    @gofree: Aside from copying and pasting that code into your themes functions.php file all you have to do is make a /css/login.css in your themes template folder.

    ReplyReply

    Comment made on December 29, 2009 at 2:59 pm

  13. gofree says:

    Very appreciated your reply. Could we have the sample .css file, please?

    ReplyReply

    Comment made on December 30, 2009 at 3:53 am

  14. Mike Jolley says:

    @gofree: I cannot give you the css, but if for example you wanted to change the logo you could use:

    #login h1 a {
    background:url(images/logo.jpg) no-repeat top;
    }

    For further CSS help I would recommend looking at W3Schools.

    ReplyReply

    Comment made on December 30, 2009 at 4:15 pm

  15. Brian Hinson says:

    Hi everyone, I saw some asking for help, and I was a little confused at firs, but it works as advertised. Here is how I used it.

    1. I copy the above code, all of the above code and put into the functions.php file, the code goes between the php begin and end marks ().

    2. You need to make a graphic to replace the original one. It is 326px wide by 67px high. I made my own.

    3. in your wordpress theme directory (of the theme you are using), create a css folder (directory, same thing). You may already have one. In that directory make a login.css file. Put your custom css in there. Here is my own custom css to make my page “look right”.

    html,
    body.login { background-color: #bbb;}
    #login h1 a { background: #bbb url(‘../images/header/login.png’) no-repeat top center;}
    #login .message { background-color: #ccc; border: 1px solid black; display:none;}
    #login form { border: 1px solid black; background-color: #ccc;}
    #login label {color: #111;}
    #login input {border: 1px solid #999;}
    .login #login p#nav a:link,
    .login #login p#nav a:visited,
    .login #login p#nav a:hover,
    .login #login p#nav a:active {color: #111 !important}

    I hope this really helps those who are having trouble.

    ReplyReply

    Comment made on January 8, 2010 at 8:26 pm

  16. Brian Hinson says:

    Oh, and you’ll notice that in my above comment, I set #login .message to display:none; This will keep that message from displaying at all!!! Just remove that style, and it will show as normal. I really didn’t need that message for my purposes.

    ReplyReply

    Comment made on January 8, 2010 at 8:29 pm

  17. Mau says:

    Thank you Brian, this code is great and your explanation makes it work ok, especially for those that are not wp-skilled like myself.

    ReplyReply

    Comment made on January 9, 2010 at 7:47 pm

Leave a Reply

Why ask?

About this site

Blue Anvil is the online web design journal & portfolio of , a web designer from Norfolk, England. Read More »
ThemeSlice
  • Featured work - More

    • Beefjack
    • Integrity
    • theotaku.com
  • Latest Tweet - More

    • Would be nice is people showed more love for MiniCard by rating it on wordpress.org http://wordpress.org/extend/themes/minicard
  • Out of the blue - More

    • MiniCard 1.1.7 Update

      I have just uploaded 1.1.7 of MiniCard here and to the WordPress theme directory. This updates includes:

      • New networks; xing, gowalla, yelp, foursquare, mobileme, google buzz
      • A way to change link text and define multiple links of the same network
      • A way to define your own custom links + icons
      • Improved admin panel

      Hope you like it, and don’t forget you can show your support by purchasing the premium pack from here.

    • Switched: From Shared to VPS

      It’s been about two weeks now since I made the transition from a shared reseller hosting account to a VPS (Virtual Private Server) account – impressions so far, excellent performance but fiddly to configure.

      The reason I wanted to change from shared hosting was the fact the server was always being hacked (even though ALL my scripts were secure), there was frequent downtime, support blamed me for problems every time, and it was slow as hell.

      Those used to a shared hosting environment would probably not know where to start when faced with configuring a VPS. Luckily, a lot of it was pre-configured when I received my account – certainly some of the major security holes were patched. I was not satisfied with those however. As a victim of hacking in the past (previous host swears it was not there fault, something I don’t believe) I took extra care to secure it as a much I could – configuring brute force detection, the firewall, installing mod security (excellent rules for that here: http://www.atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules) and going though multiple guides (like this one: http://www.webhostingtalk.com/showthread.php?t=468168) with a fine-tooth comb.

      The result? My pages are loading at least 6 times faster, I have had no down time (or at least have not noticed any), and I feel in control and happy. No longer am I at the mercy of shared hosts :)

      If your interested, I chose ServInt as my provider as they offered a great deal, as well as being a managed service (so I’m not on my own if I screw things up). I was tempted by the bells and whistles of Media Temple, but felt the ServInt service was better value.

    • Download Monitor 3.2.2 Maintenance Release

      Download Monitor has received some more love and has been updated. Here’s the change log from the new version:

      • Small bugfix in uploader.php – cat ID
      • Changed stats graph calculation – thanks lggemini
      • Changes to headers in download.php to avoid caching
      • File Browser fixes – $root was clashing with something….
      • exclude_cat works in all sections of download_page now
      • Removed hardcoding of /uploads/
      • Added action to download.php – should be able to use it to stop a download if you want – maybe limiting downloads per day or something? Whatever you want…
      • Made it so if you post new file on ‘edit’ screen, the post date is updated.
      • Fixed the ‘blank meta’ section which blanks out custom field values when nothing is set.
      • Moved ‘allow_url_fopen’ check.
      • Someone said downloads don’t work with spaces in the name. They do! Wasting my time sonny…
      • All work and no play make jolley a dull boy
      • Had to rename capabilities so they work. Apologies if you have to set this up again! Cheers to Mark Dingemanse.
      • {category_ID} custom format tag added. Useful if you want to send someone to its category on the DL page I guess. Also added {category_other} so when no category is set “other” is shown – this is because the download page can show an ‘other’ section if you want it to.
      • You can now manually edit the post date on the edit download screen.

      If you have edited capabilities for download monitor user permissions, you’ll have to again sorry! This is because I named them too long. Also, you should check your forced downloads still work because there was a logic error meaning they may not have been forced after-all…

      Enjoy.

    • Mahousive update to Download Monitor (3.2)

      Today I completed the update for the Wordpress Download Monitor Plugin – many tweaks, fixes, and features added. There were no changes to the database structure so people upgrading should be fine. Here is the list from the change log:

      • {user} tag added for custom formats
      • ‘autop’ option fix
      • Download page buttons applied with CSS so they are easier to customise/translate.
      • Fix for pagination bug after editing a download
      • Category output fix on edit downloads screen
      • Category urls on download page use ID rather than name to prevent errors when cats have the same names.
      • exclude_cat added to download_page shortcode
      • Localised ‘hits’ ‘date’ ‘title’ on download page
      • Option to disable the download logging
      • Read file ‘chunked’ some people found large files were corrupted so this should help (fingers crossed)
      • Added show_tags option to download page – displays x amount of tags on the download page.
      • File Browser root setting and download.php logic/mime types modified thanks to Jim Isaacs (jidd.jimisaacs.com)
      • Interface Improvements
      • Bulk edit categories, custom fields, tags, member only downloads
      • Added roles for download monitor admin – should be able to use with a role manager plugin if you want anyone other than admin to access the admin section e.g. http://wordpress.org/extend/plugins/capsman/
      • Change redirect after add
      • Edit Cat names/parents
      • Dedicated tags and thumbnails fields (they still use meta table though)

      And yes, those category link bugs are fixed at long last, and you can edit category names finally. Phew!