If you’re a regular visitor you’ve probably noticed the nice login form in the sidebar, which if you happen to login, will show your user name and user controls. It should work with most themes with little or no tweaking. Enjoy!
Update: This hack is no longer necessary; you can now use a beautiful widget to add the login form to your sidebar.
Update: Level 0 users always get redirected to /wp-admin/profile.php. There’s nothing I can do about this since it’s hard-coded into WordPress. Level 1 and above will return to the same page they logged in from. There is a bug open for this. Also on logout, you will always be redirected to /wp-login.php. There is a bug open for this as well.
Update 15 April: XeroCool has posted a modification for the login form for the Blix theme. I’m not sure if it works, since his own form seems to be a little misaligned. Unfortunately, even in 2005, we still can’t just write perfect XHTML and CSS and expect all browsers to render it properly. I’ll continue to keep you updated, and watch the comments section!
Update 21 April: Mark Jaquith has updated the two bugs above with patches which fix those issues, so hopefully these will be resolved in time for WordPress 1.5.1. I have also updated the code below to work with the patched WP code.
Update 25 June: I have updated the tabindex so as not to conflict with the WordPress default themes.
<li id="login">
<?php
global $user_ID, $user_identity;
get_currentuserinfo();
if (!$user_ID):
?>
<h2><?php _e('Login'); ?></h2>
<form name="loginform" id="loginform" action="<?php echo get_settings('siteurl'); ?>/wp-login.php" method="post">
<div><label><?php _e('Login') ?>:<br /><input type="text" name="log" id="log" value="" size="20" tabindex="7" /></label><br />
<label><?php _e('Password') ?>:<br /> <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="8" /></label><br />
<label><input type="checkbox" name="rememberme" value="forever" tabindex="9" /> <?php _e("Remember me"); ?></label><br />
<input type="submit" name="submit" value="<?php _e('Login'); ?> »" tabindex="10" />
<?php wp_register('', ''); ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/></div>
</form>
<?php
else:
?>
<h2><?php echo $user_identity; ?></h2>
<ul>
<?php wp_register(); ?>
<li><a href="<?php echo get_settings('siteurl') . '/wp-login.php?action=logout&redirect_to=' . $_SERVER['REQUEST_URI']; ?>"><?php _e('Logout'); ?></a></li>
</ul>
<?php
endif;
?>
</li>
Article Series - WordPress Hacks
- WordPress sidebar login form hack
- WordPress search posts and pages hack



Facebook
Digg
del.icio.us
reddit.com
Newsvine
(4 votes, average: 4.75 out of 5)


24 Trackbacks/Pingbacks
April 15, 2005 10:43 am
April 15, 2005 11:49 am
April 24, 2005 4:27 am
June 11, 2005 4:00 pm
November 15, 2005 9:09 pm
November 21, 2005 9:55 am
December 20, 2005 9:47 pm
March 10, 2006 8:01 pm
March 27, 2006 9:47 am
May 29, 2006 5:05 pm
September 27, 2006 1:46 pm
October 14, 2006 11:16 am
October 24, 2006 10:56 pm
October 25, 2006 1:03 am
November 20, 2006 8:37 pm
January 21, 2007 12:52 pm
March 7, 2007 5:02 am
March 26, 2007 5:25 am
March 27, 2007 9:51 pm
April 23, 2007 8:35 pm
May 25, 2007 9:16 pm
May 28, 2007 3:33 am
July 12, 2007 10:47 am
February 14, 2008 7:50 am
79 Comments
Works absolutely awesomely! I’m definitely stealing this for my site. :D
Nice one! It works just instantly! :)
Got it online on my site now :D
Thanks again!
ioerror, Can you show a screenshot and what resolution and browser? It seem to work fine in FireFox and IE. Maybe CSS might help, but I need to know the prob or see a screenshot.
XeroCool, I’ve e-mailed you the screenshot you asked for. I hope it helps in figuring out what’s going on. Drop by on IRC if you need any live assistance.
There is one small error with the Journalized series with this hack.
/wp-login.php" method="post">
:
:
»" tabindex="3" />
">
Is what I used. The echo user_id made that happen way out in the middle of the page in 800*600 browser.
Perfect – thank you!
I’ve made it work with the Blix theme (or, sort of, I’ve made a total remake of the theme but I got the same error that XeroCool had. Take a look at my site, and let me know if you want the “minimized edit” that I have… (really, I’ve just removed code, and now it works for me).
Hi
You have a small problem here:
‘/wp-login.php?action=logout&redirect_to=’ . $_SERVER['REQUEST_URI']; ?>”> because it doesn’t close the link. It needs a closing </a>.
I am using this for my site, a bit modified.
Kind regards.
William, you’re quite right. The </a> was dropped in error the last time I pasted the code in. I’ve added it back. Thanks for letting me know!
This is a great thing to have on a site, but the XHTML does not validate for me when I just paste what you have here. Yet, when I check the XHTML validation of your site, it doesn’t come up with the same errors. I’m curious: are you perhaps using a different version for your own sidebar?
The problem is with one part of the code.
'/wp-login.php?action=logout&redirect_to='Can I just use the & amp ; code here? I don’t know enough about PHP yet to know. >_
I ran your site through the validator, and you have quite a few problems, but this is not caused by the sidebar login form. It is caused by the fact that you have <div id=”sidebar”> appearing twice (i.e. the first error on the validator’s response). Fix that and most of the rest should go away.
I know this. *laughs* That would be why I’m currently going through it all. I’m switching several files right now, too, so had I known you were actually online right now, I probably would have refrained from posting the message. ;) :p Anyway, I located the error. :) Sorry for the inconvenience!
I was wondering if this could be further improved to have the (once logged in), users avatar where it says logout and admin. That would be really cool :)
Hey guys, sounds nice… but I can’t find a download link dor the sidebar login!
Woah!!!
Did great on my website…
Thanx a million
Sounds just like I was looking for, but like Don of number 18 above, I can’t find the sidebar login hack script either. Is it a Rove double secret sort of hack?
You’re kidding, right? It’s very hard to miss.
re. You’re kidding, right? It’s very hard to miss.
Well no IO Error.. I can only assume that’s it under ‘Update 25 June ‘ starting with But what file does the hack go in. Not like I’m unfamiliar with php, but am a newbie to wordpress… Prior thx if you could clear that up for me – it’s is a nice hack..
Does the hack go in sidebar.php???
I got it – If only I had a brain as the Scarecrow says.. thx though for the hack IO Error!!
Simplicity and brilliance – well thought out and an excellent mod!
I’ll buy you a beer sometime.
Rich
You rock – although you know that already J ..
Thanks excellent mod!
Do you also have a Wordpress mod for the sidebar where you can see how many visitors and how many members are currently on the weblog? I can’t find one.
This is a great mod. Even with my non-knowledge of PHP I got this running. Thanks for this.
Just one question. When I log-out it redirects me to the wp-admin.php. Is it possible to change this to my homepage?
Thanks in advance!
Any way to add a link for “Forgot Password” Next to the “Register” bit?
Arnaud, go scroll to the top of the page and read the post.
Karen, I suppose you could add a “Forgot Password” link. It would be rather long, though, and make the form kind of crowded.
sorry but I haven’t a clue how to install this hack…
My wp installation is members only behind a firewall – intranet employees only if you get the picture. I want to enable anyone to create a post with the idea of using posts as tasks that all employees can comment on.
Is there anyway to remove the auth requirements or enable anonymous posting? Also once that is accomplished is it possible to provide a minimalist screen for posting without showing all the other admin links?
thank
I’ve pasted the code to my sidebar.php theme, but i don’t get the register link
http://millesabords.info/wp2bas/
Sorry, i only have to enabled visitor to register
Super cool !!! I have used it in my site :D
http://www.raasmzone.com
Thanks for sharing
help! i can’t figure out how to add a login box
This is only for the sidebar within the wordpress folder, If i place it in outside of WP, it will login BUT will not display user info and logout
thanks a lot, exactly what i was looking for …
Thanks for the great code! I just have one question. Is it possible to use the “remember me” check box, or will this only work with the default Wordpress login page?
The “Remember me” feature is new to WordPress 2.0, and I haven’t gotten around to integrating it yet.
hello, can anyone provide me a different link to the blix modification? the xerocool link seems to be down?
thank you very much
I am trying to get a login page to come up before users can access the main “Word press” blog page. I tried copying the above code into the index.php file but with no luck…please help.
Thanks!!
Awesome! Great work!
Does anyone still have the modification for Blix theme? the download link for it is down. Thanks!
Works like a charm! Thank you!
hello. i put this useful plugin to my site: umutdogan.com.
But i couldn’t change text size as my other sidebar elements.
i tried but it didn’t work.
thanks ;)
Great script, I have actually used it for quite a while now and felt the need to simplify it a bit for my own use hence a plugin. See my post describing it and visit the site to see it on the sidebar.
I’ll be trying to bring the lost password recovering into the sidebar as well without going to the default WP page.
It would be perfect if there are geeks out there who can brush up the plugin with Ajax tricks such that logging in/out without refreshing of the page. This shouldn’t be too difficult should it? (to me something yet to be learnt!).
Thanks again for the original scripts.
Is it possible to display the Write, Manage, Profile link in between the site admin and log out link after users logging in? Cause it would be more convenient to click Write link on the main page rather than going to Site Admin=>Dashboard=>Write =)
Anyone know how to make this work with the sidebar widget?
Hi,
Is it still not possible to override redircting to the ugly wordpress login page when you enter the wrong login password? Logging in and out work great, my users are able to stay on my site.
However they enter the wrong password/username they get redirected to that god awful page.
Thanks
I hear you! I am looking for the same thing.
I don’t know enough about php to know how to fix this but is there no way to redirect to another page/link if the wrong pass is entered?
BTW – This is a great plugin Michael!
This is awesome!! Thanks!
Works great for my site! Thank you so much!
Hey, I installed the script w a little size mod, works great. I also added a “Lost password?” link and moved “Register” a line down to make it align better. Here are screenshots of the and of the login.
OK so I messed that one up a little, you get the picture though.
How do I edit the look of the plugin. I have a big white space that does not go with the background. I am new to all this so please be kind. :)
Nevermind….I got it!!! :) Thanks for the plugin.
Thanx alot for this!
Umm, seriously, where’s the download link?
I can’t see a download link for this… Maybe it needs making a little less… stupid?
There is no download link. Why are you asking for a download link?
So its just the code above..? That wasn’t clear as others refer to it as a ‘plugin’ . Where does one paste the code to? I’ve tried it in sidebar.php and it doesn’t work there… I need installation instructions. Sorry if I’m missing the obvious.
Nice! Thanks for this! But I am facing one problem as i am using frames in my page! This feature works perfect in Firefox, but when i open IExplorer, this only works if i open just blog page (), but if i open which opens blog in frame, then it somehow doesn’t login – it just refreshes the frame and thats all!? Any ides why? Thanks!
Thanks a bunch for the code I really like it! I had to modify it a bit to get it right for me but that wasn’t hard at all xD
I have one question, I have a * next to the login panel that I can’t seem to get rid of. I can’t see it in the code at all. Here is what I mean –
Just wondered if anyone else had that problem or if they knew how to get rid of it.
Hi fluke! You need to delete tags or edit your css file.
And now my little problem:
Everything is ok in FF and in Opera but IE tells me that something is wrong. The main page is shown just below the line when the login panel ends. I tried to fix it out by removing tags, but is doesn’t work.
(Sorry for my Polish-English:P)
Any ideas?
hey I had this problem too.. There’s something wrong with Michael Hampton’s code when displayed on IE and I posted for help in wordpress forum, another user sfong15 recommend me to use this instead, and it worked really well yupps try it out..
How do you make it so when you login, it takes you to “your” dashboard ..
If you want to go to your dashboard when you login, remove this hack and restore the original code. :)
Love this hack, just had to extend my kudos. Notice I called it a hack? That is the correct terminology isn’t it? It is not a plugin, right? I just want to show proper etiquette.
This is every bit as cool as the SexyComments plugin by BorkWeb:
http://borkweb.com/story/wordpress-plugin-sexy-comments
Some of your users should have their doctor check for brain lesions. I’ve had some problems with those recently. After pasting this in to my sidebar (Senorita theme) I am presented with a link to go to my Dashboard if I so choose, or logout, nice!
Hi I was wondering if there’s any way to add this to comments.php… what I’d really like is a login right there so when my blog contributors want to post a comment but haven’t logged in already, they can just do it right there.
I put it in the comments.php and it looked look and I thought it would work, but when I press login it tries to post a comment and I get an error saying “Please type a comment”. When I typed a comment and tried it, it posted an anonymous comment and didn’t log me in. Must be some sort of conflict or confusion with the comments.php code, I guess. I’d appreciate any help, because I’m new to php and winging it.
A marvellously simple fix… thanks for sharing…
I love this hack !!! Good job …
Yes, this sidebar login hack is GREAT! Like the posters above I would love to see
1. Ajax login/logout feature.
2. Way to add this login/logout feature in the commments section, of course, with Ajax incorporated.
Thanks!
Is there anyway to use this without enabling register ? I notice when register is turned off the login form doesn’t appear, is there another way to set it up so it doesn’t require register to be enabled ?
hi… it is working but i’m using this in a MUwordpress… what i must to do to a redirection to the user dashboard after login. thanks
How can I make the login form in a horizontal style?
Easy. You just remove the little “”’s where they shouldn’t be. That’s also pretty easy to figure out
Oops. It removed the html tags.
in other words,
little-arrow-pointing-to-the-left,
B R
little-arrow-pointing-to-the-right.
There.
I find an issue, when you open a new IE window and login the first time, it will say cookie problem, but the second time will be ok, this only happens when you open a new IE window and login the first time, could you fix this problem? thanks!
I can’t fix IE. Only Microsoft can do that, and they don’t seem to be inclined to actually fix things.
Nice one just what i needed thanks a lot!
Post a Comment