Using jQuery to liven up your WordPress login
When I’m coding a project for a client, I always try make using the site as easy as possible. Whether it be using custom fields to automate the use of images in a post, or coding wp-admin pages to make the writing of posts & pages easier for them to do. Less is more… So in applying this principle, I’m going to show a really quick method of simplifying the clients login process using a jQuery lightbox.
Here’s a demo of what we’re going to do.
Just in case you’ve been coding in a box for the last 10 years, jQuery is a great JS library that has a number of nifty usages. One of its popular plugins is the ‘thickbox‘ and its what we’re going to use now to create a simple means of logging in for you/your clients.
Prepare your site
In your header.php file you need to include 3 files: jquery.js, thickbox.js and thickbox.css. Then upload the included loading.gif animation to your images folder. The includes for these files would look like this:
<script type="text/javascript" src="<? bloginfo('template_directory'); ?>/jquery-latest.pack.js"></script> <script type="text/javascript" src="<? bloginfo('template_directory'); ?>/thickbox-compressed.js"></script> <link rel="stylesheet" type="text/css" href="<? bloginfo('template_directory'); ?>/thickbox.css" media="screen" />
NOTE: call the jquery file before the thickbox.js file.
Then open your thickbox.js file and edit the path to your theme’s images folder. It’ll look something like this:
var tb_pathToImage = "/wp-content/themes/yourtheme/images/loadingAnimation.gif";
Ok, now your site is thickbox’d. Nice.
Make it happen
Of the many usages of the thickbox, the one we’re going to use now is the thickbox for Inline Content. In essence, you’re going to have your login form somewhere on your page (preferably in an element that is included on every page on your site like your sidebar) but its going to be hidden by an inline CSS style:
<div id="form" style="display:none;">
Somewhere else on your page, you’re going to have a link (like in your topnav) that when clicked, will open that hidden div/form in the thickbox. This link will have, instead of a URL as its href target, some magic thickbox commands that will summon your hidden login form. The link would be as follows:
<a href= "#TB_inline?height=200&width=200&inlineId=form" class="thickbox" title="Login to the WP Guru site">Login</a>
What’s happening here is that the link is calling an inline div that’ll be displayed in a thickbox with the sizes specified and you’re identifying the inline div ID that will be called. Note that class=”thickbox” is critical to the thickbox’s successful usage.
The login form
The actual login form can be simplified down to its core elements so that you have nice neat code made up of only what you need. You can of course tweak this to be just what YOU need. The actual login form is found around line 378 in the wp-login.php file (v2.5).
<div id="form" style="display:none;"> <form name="loginform" id="loginform" action="http://wpguru.co.za/wp-login.php" method="post"> <p> <label>Username<br /> <input type="text" name="log" id="user_login" class="input" value="" size="20" tabindex="10" /></label> </p> <p> <label>Password<br /> <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label> </p> <?php do_action('login_form'); ?> <p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> Remember Me</label></p> <p class="submit"> <input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Log In'); ?>" tabindex="100" /> <input type="hidden" name="redirect_to" value="/" /> <input type="hidden" name="testcookie" value="1" /> </p> </form> </div>
You can of course style up the div that contains your form with your site logo etc to make the whole login process seem even more bespoke.
TIP: You can set the overlay color of your jQuery thickbox (default set to 75% black) to match your site, in line #39 of your thickbox.css file.
Viv
Hey, this is cool! I have done all these steps, though, and my thickbox is coming up just fine- but there is no login form in it. I’m a semi-new self-taught gal on this stuff and I’m not sure if there is something I have to do to the wp-login.php file in the main folder? It seems like that’s missing piece. (Sorry if this is a dumb question!)
Chris M
Nifty little trick. I’ve actually done some similar things for clients before, but found myself going the full mile and totally customizing the entire dashboard just to keep the user away from the whole BANG WORDPRESS appearance.
I will give the jquery stuff a read – I’ve been coding since I was 7yrs old and now I think I might have been in the box, well at least according to you
Thanks for a interesting post,
iMod.co.za
MarkB
Hi Viv!
You need to duplicate the form FROM your wp-login.php page into your theme files and put it in the #DIV that you’re showing in your thickbox. So when the thickbox appears, it’ll display the login form.
IE, the last code snippet in this article, the login form, must be inside your hidden DIV that you show inside your thickbox…
There’s no need to touch your wp-login file
Let me know if you come right?
Deenworks
Hey Marky,
Awesome.. luv it.. jquerys’ thick box is better scriptolicious etc.. much faster. Also another way is to use accordion.. ? (I can think of half a dozen ways to improve logins)
But that for next time.
Marek | Deenworks.com
BeyondRandom
Awesome…you sir are a badass!! This what i was looking for all day! Thanks a million!
MarqueDigital
Very nice!
dennis
Nice, only 1 thing, when i’m logged in i get a refresh to the homepage instead of the page i called the login function. Is there a way to work around this?
Andy
Does anyone know if I can do this with Shadowbox?
I have conflicts with other plugins and thickbox
Michel
As far as I can tell, the Demo doesn’t work without JS, and that’s a serious issue. In case JS is disabled/unavailable, a simple html login form should open instead (AJAX best practices). Otherwise, you’re building something which won’t work in some cases…
blessing
OMG!! I’d been looking for this all day! thank you!
Rolf
Is there a way to have the login link change to logout once you have logged in ?
Rafael
Nice write up…usually I never reply to these thing but this time I will,Thanks for the great info.
SLOW HAND
Just make a plugin for noobs……. please
Roy37
Let me give you several examples: When you are sports fan you are united to that team. ,
Bill Robbins
Thanks for making this. I took the principle and added it to Fancybox jquery since I was already using it.
Puneet
I face one problem in following your example. I have placed the files on server, linked them into header. Instead of hard coding the wp-login.php file, I included the form code in the sidebar as invisible(with div id=”form”). But when I click my link placed on navigation bar, nothing seems to happen. Please help me out.