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>
M. Jones
Apr 14, 2005
Works absolutely awesomely! I’m definitely stealing this for my site. :D
Ross
Apr 14, 2005
Nice one! It works just instantly! :)
Got it online on my site now :D
Thanks again!
Apr 15, 2005
r0x0rz » WP Hack: SideBar Login Form
XeroCool
Apr 15, 2005
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.
Michael Hampton
Apr 15, 2005
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.
Apr 15, 2005
Weblog Tools Collection » WP Hack: Sidebar login form
Lord Anki
Apr 15, 2005
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.
Jess
Apr 16, 2005
Perfect – thank you!
Andreas Viklund
Apr 16, 2005
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).
Apr 24, 2005
7 seconden » Gebruikte WordPress Plugins
William
May 03, 2005
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.
Michael Hampton
May 04, 2005
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!
Lelia Katherine Thomas
Jun 05, 2005
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. >_
Michael Hampton
Jun 05, 2005
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.
Lelia Katherine Thomas
Jun 05, 2005
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!
Usayd
Jun 08, 2005
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 :)
Jun 11, 2005
Little Storping-in-the-Swuff » IO ERROR » WordPress sidebar login form hack
Dan
Jun 25, 2005
Hey guys, sounds nice… but I can’t find a download link dor the sidebar login!
Kaysha
Jul 08, 2005
Woah!!!
Did great on my website…
Thanx a million
Adnihilo
Jul 22, 2005
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?
Michael Hampton
Jul 22, 2005
You’re kidding, right? It’s very hard to miss.
Adnihilo
Jul 29, 2005
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..
Adnihilo
Jul 29, 2005
Does the hack go in sidebar.php???
Adnihilo
Jul 29, 2005
I got it – If only I had a brain as the Scarecrow says.. thx though for the hack IO Error!!
Richard Brown
Aug 09, 2005
Simplicity and brilliance – well thought out and an excellent mod!
I’ll buy you a beer sometime.
Rich
Steve
Sep 29, 2005
You rock – although you know that already J ..
Vincent
Oct 08, 2005
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.
Nov 15, 2005
Customizations for WordPress at PharmacyIT
Nov 21, 2005
Because I Write » Login box at sidebar
Arnaud
Nov 23, 2005
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!
Karen
Nov 28, 2005
Any way to add a link for “Forgot Password” Next to the “Register” bit?
Michael Hampton
Nov 28, 2005
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.
Dec 20, 2005
Notes of Future Master » ãƒã‚°ã‚¤ãƒ³æ™‚ã?®ã?¿è¡¨ç¤ºã?•ã?›ã‚‹æ–¹æ³•
bob
Dec 31, 2005
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
MilleSabords
Jan 23, 2006
I’ve pasted the code to my sidebar.php theme, but i don’t get the register link
http://millesabords.info/wp2bas/
MilleSabords
Jan 23, 2006
Sorry, i only have to enabled visitor to register
Sidd
Jan 30, 2006
Super cool !!! I have used it in my site :D
http://www.raasmzone.com
Thanks for sharing
winston
Mar 09, 2006
help! i can’t figure out how to add a login box
Mar 10, 2006
aNieto2K » Hack Login más visible
Aki
Mar 11, 2006
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
Mar 27, 2006
jk-digital.com
deltanine
Mar 30, 2006
thanks a lot, exactly what i was looking for …
hdtv freak
Apr 05, 2006
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?
Michael Hampton
Apr 05, 2006
The “Remember me” feature is new to WordPress 2.0, and I haven’t gotten around to integrating it yet.
Brian
Apr 11, 2006
hello, can anyone provide me a different link to the blix modification? the xerocool link seems to be down?
thank you very much
DKD
May 08, 2006
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.
Carrie
May 16, 2006
Thanks!!
May 29, 2006
urlher.net » Huskelapp:
iBrev
Jul 20, 2006
Awesome! Great work!
Tada
Jul 30, 2006
Does anyone still have the modification for Blix theme? the download link for it is down. Thanks!
Stian Domben BÃ¥rdsen
Sep 05, 2006
Works like a charm! Thank you!
Umut Dogan
Sep 25, 2006
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 ;)
Sep 27, 2006
arseneault.ca
Oct 14, 2006
Blogging Web 2.0 Technology Website | Tech Tips | Learning | Networking Tips | Web Design | SEO | AJAX » WordPress sidebar login form hack for Blix Theme
sfong15
Oct 24, 2006
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.
Oct 24, 2006
arseneault.ca » Blog Archive » Adding a ‘login’ box in a WordPress sidebar
Oct 25, 2006
Because I Write » Blog Archive » links for 2006-10-24
Nov 20, 2006
Because I Write » Blog Archive » ezLogin plugin
silverelf
Dec 12, 2006
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 =)
John
Dec 18, 2006
Anyone know how to make this work with the sidebar widget?
Mark
Jan 14, 2007
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
Will
Jan 17, 2007
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!
Jan 21, 2007
HAKKICEYLAN » Blog Archive » Tab GeçiÅŸlerindeki Problemler
Josh
Jan 27, 2007
This is awesome!! Thanks!
crizatu
Feb 03, 2007
Works great for my site! Thank you so much!
Sam
Feb 16, 2007
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.
Sam
Feb 16, 2007
OK so I messed that one up a little, you get the picture though.
Melissa Odom
Feb 24, 2007
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. :)
Melissa Odom
Feb 24, 2007
Nevermind….I got it!!! :) Thanks for the plugin.
sesom
Mar 03, 2007
Thanx alot for this!
Mar 07, 2007
VoipBloggen : Ting som gør det sjovt at bruge Voipbloggen
Raymond
Mar 07, 2007
Umm, seriously, where’s the download link?
Stevenki
Mar 09, 2007
I can’t see a download link for this… Maybe it needs making a little less… stupid?
Michael Hampton
Mar 09, 2007
There is no download link. Why are you asking for a download link?
Stevenki
Mar 10, 2007
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.
Mar 26, 2007
Because I Learn » Blog Archive » My first plugin
Mar 27, 2007
Because I Learn » Blog Archive » Login form at sidebar
domkrats
Apr 05, 2007
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!
fluke
Apr 07, 2007
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.
krzysztof114
Apr 12, 2007
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?
silverelf
Apr 13, 2007
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..
Kevin
Apr 22, 2007
How do you make it so when you login, it takes you to “your” dashboard ..
Michael Hampton
Apr 22, 2007
If you want to go to your dashboard when you login, remove this hack and restore the original code. :)
Apr 23, 2007
Links da semana #002 by BlogAjuda
Flash Buddy
Apr 25, 2007
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!
May 25, 2007
Useful, But Rarely Used WordPress Techniques » WPDesigner
May 28, 2007
Casella di login wordpress personalizzata : worldpress| 4 stars blog
Tyler
Jun 10, 2007
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.
Tim
Jun 14, 2007
A marvellously simple fix… thanks for sharing…
Andrey
Jun 28, 2007
I love this hack !!! Good job …
Tome
Jul 01, 2007
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!
Jul 12, 2007
BlogAjuda » Formulário de login no blog
alias
Aug 10, 2007
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 ?
yli
Aug 29, 2007
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
Ruriko
Dec 23, 2007
How can I make the login form in a horizontal style?
n00b
Dec 28, 2007
Easy. You just remove the little “”’s where they shouldn’t be. That’s also pretty easy to figure out
n00b
Dec 28, 2007
Oops. It removed the html tags.
n00b
Dec 28, 2007
n00b
Dec 28, 2007
in other words,
little-arrow-pointing-to-the-left,
B R
little-arrow-pointing-to-the-right.
There.
xyhzc
Dec 31, 2007
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!
Michael Hampton
Dec 31, 2007
I can’t fix IE. Only Microsoft can do that, and they don’t seem to be inclined to actually fix things.
Illy
Jan 01, 2008
Nice one just what i needed thanks a lot!
Feb 14, 2008
Mr. WordPress - Exibindo elementos apenas para usuários cadastrados