Easy user registration and login/logout in WordPress without plugins
Let users register and login from your front page
Only a few days after launching my new blog design, I’ve already received a couple of e-mails from other WordPress users asking me how I implemented the registration and login function of my blog from the front page, and the answer couldn’t be any simpler. Using a few simple preset PHP functions and a couple of specific name values, we can let users register, login and log out from anywhere we want.
Overview
Both functions rely on a set of specific form and input names, sent to a specific parser. For example, since my domain is steelfrog.com, my login and registration requests are parsed on http://www.steelfrog.com/wp-login.php.
Demonstration
You can try it out right here! Just scroll up and check out the top-left portion of your screen. Click the question mark icon to register, or if you’ve already done so, simply login right at the top of the page.
Login/Logout
WordPress has a built-in function to return your site’s login and logout URLs. They are:
wp_login_url()
wp_logout_url()
Using those functions, we can easily create a customized login form and by checking if the user is already logged in, we can present the logout button. Let’s take a look at an example form, and then decipher it.
<?php if ( is_user_logged_in() ) { ?>
<a href="<?php echo wp_logout_url(get_permalink()) ?>">Logout</a>
<?php } else { ?>
<form id="login" method="post" action="<?php echo wp_login_url( get_permalink() ) ?>">
<fieldset>
<label>Username
<input type="text" value="" name="log" /></label>
<label>Password</label>
<input type="password" value="" name="pwd" /></label>
<input type="submit" />
</fieldset>
</form>
The first thing we do is check if the user is logged in by running if ( is_user_logged_in() ). If the user is logged in, then we present the logout button. If he’s not logged in, then we present the login form. I’ve added the get_permalink() function to the parameters, which will redirect users to the current page once they hit submit and their credentials are checked.
The form itself is quite simple. The parser checks for specific name values, so it’s important to keep the form and label names. That’s all their is to the login form, and logout button.
Registration
Registration, much like the login and logout form, is quite simple and relies on a few key elements.
<form name="registerform" action="http://www.steelfrog.com/wp-login.php?action=register" method="post">
<fieldset>
<label>Username
<input type="text" name="user_login" value="" /></label>
<label>E-mail
<input type="text" name="user_email" value="" /></label>
<input type="hidden" name="redirect_to" value="" />
<input type="submit" name="wp-submit" />
</fieldset>
</form>
The form’s action points to your blog’s login URL, with the action=register parameter. The rest of the form functions like the login and checks for name sets.
That’s all there is to it. Implement to your sidebar, header or in your content, style accordingly and enjoy.
Follow-up
I’ve noticed that WordPress 3.0 also implemented a function that does this. I’m still looking into the best way to use this.
<?php wp_login_form( $args ); ?>
Notice: this article was written for WordPress 3.0
While it is unlikely that near-future revisions of WordPress will break these functions, it still remains a possibility. If you are running a busy blog, you may want to keep this in mind before implementing the feature, or at least keep a close eye on it after updates.

NewMediaSolutions
July 29, 2010 at 3:06 PMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-77
Excellent information! We searched Google for a long time before we were able to find your website with the registration information. We just couldn’t find it anywhere else! Thanks again!
Roy
October 21, 2010 at 2:27 PMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-386
I’ve seen several of this implementation but if you enter something wrong or you leave it blank and click on submit, it will still direct you to the WP standard login page. Now the question is how to get around that by somehow retrieving the error messages and display it on the same page as the login/register.
roy
April 20, 2011 at 5:46 PMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-611
i;m not sure how i got to this easy user page or what it is for please respond and let me know .possible somebody using my info
Sagive
November 24, 2010 at 2:35 PMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-398
Yee!! thanks man.. been looking for such a clear explenation..
i want to use such a “register” box that has 2 feilds to
register new users to me website “EMAIL LIST”…
the wrong approach?
Natural Vitamins
December 3, 2010 at 12:51 PMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-401
when it comes to video games, i enjoy playing those that have very nice graphics and story like Plantz and Zombies *::
gala
January 19, 2011 at 1:23 AMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-574
I hope this works with 3.0.4 v of wordpress. Do you have any suggestion if your templates doesn’t support register-login? Thanks a lot with this article. Great Job!
Joe
May 24, 2011 at 2:25 AMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-618
How about the expandable form action? I really would like to do that with the form.
Thanks!
Kristiyan Lukanov
July 21, 2011 at 6:16 AMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-623
I’m searching for a custom wordpress registration page, and this setup here is so simple and customizable.
Thanks for the info.
amit
July 22, 2011 at 7:59 AMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-624
i don’t know why, but the basic steps like where exactly put the code above is not mentioned any where. i am totaly lost in which files of wordpress should all this customiation put?
Harold
September 11, 2011 at 12:58 PMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-634
Can you tell me where this code would go?
I don’t know which page to put this on, but it looks amazing!
vanessa
November 11, 2011 at 10:54 AMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-645
how do we go about into adding extra fields in the register form? Like phone number ? I’m sure we’ll probably have to edit the tables in wordpress.
lanzon
January 19, 2012 at 9:26 PMhttp://www.steelfrog.com/easy-user-registration-and-loginlogout-in-wordpress/#comment-651
hi guys im simple person bt malibog hehehehe tra usap tau