Create custom wordpress registration page
I am sure, most web masters using wordpress do not like to let their users to signup or login through the boring wordpress default signup/login screens. Everyone would like to make those pages look like same as part of their website. Today we will have a little play with creating a WordPress custom registration page template. You may not forgot my last tutorial about creating a custom wordpress login page template as part of the theme. If you hadn’t read it yet, read it here Custom WordPress Login without using a plugin
Ok, now we will move in to our today’s tutorial.

Step1: Create page custom-register.php
First we will create a new php template file called custom-register.php and place it inside your wordpress theme folder your-domain-name/wp-content/themes/your-theme-name
Step2: Naming the Template file
< ?php /* Template Name: Custom WordPress Registration */ ?>
Step3: check if the user is not logged in
Like we did for custom login, we must first check whether the current user is logged in or not. We will show the registration form only if the current user is not logged in. Additionally, we need to include the file registration.php from wp-includes folder in order to create a new user inside wordpress system.
require_once(ABSPATH . WPINC . '/registration.php');
global $wpdb, $user_ID;
if (!$user_ID) {
//All code goes in here.
}
else {
wp_redirect( home_url() ); exit;
}
Step4: Embedding the Register Form and jQuery Ajax
Before we display the register form we need to check whether the user registration is allowed by the administrator using the function get_option('users_can_register').
<?php
if(get_option('users_can_register')) {
//Check whether user registration is enabled by the administrator
?>
<?php the_title(); ?>
<div id="result"></div> <!-- To hold validation results -->
<form action="" method="post">
<label>Username</label>
<input type="text" name="username" class="text" value="" /><br />
<label>Email address</label>
<input type="text" name="email" class="text" value="" /> <br />
<input type="submit" id="submitbtn" name="submit" value="SignUp" />
</form>
<script type="text/javascript">
//<![CDATA[
$("#submitbtn").click(function() {
$('#result').html('<img src="<?php bloginfo('template_url') ?>/images/loader.gif" class="loader" />').fadeIn();
var input_data = $('#wp_signup_form').serialize();
$.ajax({
type: "POST",
url: "",
data: input_data,
success: function(msg){
$('.loader').remove();
$('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow');
}
});
return false;
});
//]]>
</script>
<?php
}
else echo "Registration is currently disabled. Please try again later.";
?>
Step5: Validate the inputs and register the user
Add the following php code inside if (!$user_ID) { } and move the register form inside the else part of the following if condition.
if($_POST){
//We shall SQL escape all inputs
$username = $wpdb->escape($_REQUEST['username']);
if(empty($username)) {
echo "User name should not be empty.";
exit();
}
$email = $wpdb->escape($_REQUEST['email']);
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
echo "Please enter a valid email.";
exit();
}
$random_password = wp_generate_password( 12, false );
$status = wp_create_user( $username, $random_password, $email );
if ( is_wp_error($status) )
echo "Username already exists. Please try another one.";
else {
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
wp_mail( $email, $subject, $msg, $headers );
echo "Please check your email for login details.";
}
exit();
}
else
{
//Embed the register form and javascript here
}
In the above code, we will validate the inputs and then create random password with the use of function wp_generate_password(). With the use of wp_create_user function create a new user account if not the username already exists in the system. Finally, we will email the login details including the random generated password to the signed up user.
Full Code Preview
< ?php
/*
Template Name: Custom WordPress Signup Page
*/
require_once(ABSPATH . WPINC . '/registration.php');
global $wpdb, $user_ID;
//Check whether the user is already logged in
if (!$user_ID) {
if($_POST){
//We shall SQL escape all inputs
$username = $wpdb->escape($_REQUEST['username']);
if(empty($username)) {
echo "User name should not be empty.";
exit();
}
$email = $wpdb->escape($_REQUEST['email']);
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
echo "Please enter a valid email.";
exit();
}
$random_password = wp_generate_password( 12, false );
$status = wp_create_user( $username, $random_password, $email );
if ( is_wp_error($status) )
echo "Username already exists. Please try another one.";
else {
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
wp_mail( $email, $subject, $msg, $headers );
echo "Please check your email for login details.";
}
exit();
} else {
get_header();
?>
<!-- <script src="http://code.jquery.com/jquery-1.4.4.js"></script> -->
<!-- Remove the comments if you are not using jQuery already in your theme -->
<div id="container">
<div id="content">
<?php if(get_option('users_can_register')) {
//Check whether user registration is enabled by the administrator ?>
<?php the_title(); ?>
<div id="result"></div> <!-- To hold validation results -->
<form action="" method="post">
<label>Username</label>
<input type="text" name="username" class="text" value="" /><br />
<label>Email address</label>
<input type="text" name="email" class="text" value="" /> <br />
<input type="submit" id="submitbtn" name="submit" value="SignUp" />
</form>
<script type="text/javascript">
//<![CDATA[
$("#submitbtn").click(function() {
$('#result').html('<img src="<?php bloginfo('template_url') ?>/images/loader.gif" class="loader" />').fadeIn();
var input_data = $('#wp_signup_form').serialize();
$.ajax({
type: "POST",
url: "",
data: input_data,
success: function(msg){
$('.loader').remove();
$('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow');
}
});
return false;
});
//]]>
</script>
<?php } else echo "Registration is currently disabled. Please try again later."; ?>
</div>
</div>
<?php
get_footer();
} //end of if($_post)
}
else {
wp_redirect( home_url() ); exit;
}
?>
Once the template file is ready, you need to create a new page from the wordpress admin. If you are unsure about this just follow the step number 10 from my previous tutorial Custom WordPress Login without using a plugin. Hope you find this tutorial useful.










How would I add additional fields to the registration for example an address?
Thank you, I may use this in our coming web site.
Can you guide more detail,thanks.^^
Hey There, Love your tutorials for the custom wordpress pages! Fantastic, thanks so much for taking the time to create them! I have one for you! Now that we all know how to create a custom Login Page, Registration Page and password reset page… What about a custom Profile page? So if the user has registered, they can then go and change their password, or update their email at some point…
Only if you can be bothered of course!
Thanks again!
Amazing work, maybe you can complete the master piece with 2 pages more, one is custom page to actualize user dates and add a custom avatar, and the second page, custom page to user post content, basic ( title, desc, 1 image, select category and send)
VERY THANKS FOR THE AMAZING TUTS
hi
After creating file & page I get fatal error message
Fatal error: Call to undefined function wp_get_current_user() in ..wp-includes\capabilities.php on line 1206
can you help me?
thx
Sir,
It is not working. Plz guide me.
I think you shouldn’t include registration.php because it’s “deprecated” since WordPress 3.1. All functions of this file can be now located in user.php… Please tell me if I wrong about this
Thanks for the heads up, Newman Barreto!
I will soon update the post.
Good article, but like Newman said. The registration.php must be replaced with user.php in order to make it work with WordPress 3.1 or higher. One more small issue, when you check the $_POST from the form, it should have a hidden field to specific which form of the post was sent from. This will help avoid lot of conflicts with some plugins might have the same use of if($_POST).
Is there a reason why my wp_create_user() command only works when I reload and resend the page? For the life of me I can’t figure out why the user doesn’t get registered on the first submission and then when you click reload page and accept to resend the data, the user gets created! Any ideas?
Do you know any registration form plugins that can send the submitted info to a database instead of just email?
after creating file and Page ,i have some Error in Line 86.Can u help e ?? plz. i’ using wordpress 3.4. thank’s
Im getting this same error on line 86:
Parse error: syntax error, unexpected ‘}’ in register.php on line 86
The theory is good but this code is seriously sloppy and very badly written. Why would you include header and footer inside a conditional? Why would you exit the code? Why is the tabbing mutilated?
If I was a beginner this code would only confuse me.
Parse error: syntax error, unexpected ‘}’ in /home/content/88/10160188/html/wp-content/themes/online-marketer/custom-register.php on line 86
Thanks for the plugin
Please help me, after making page and put the custom sign up template it redirect me to the homepage? I already change the registration.php to user.php. Any idea?
Parse error: syntax error, unexpected ‘}’ please help me
Hi! My partner and I frequently publish guest articles or blog posts for other blog owners to help
increase publicity to our work, as well as provide
superb content to website owners. It really is a win win situation!
If you are interested feel free to contact me at:
chester-castillo@gmail.com so we may communicate further.
Appreciate it!
It is compatible. The only reason why the plugin author hasn’t updated the plugin’s read me file is because they haven’t come out with new features yet. It works just fine.
Good tutorial but how can I use password field?
Awesome things here. I am very happy to look your article.
Thank you a lot and I am taking a look ahead to touch you.
Will you kindly drop me a e-mail?
This “emptyempty($username)” you must change to “empty($username)”
Where would I start to look to make it so people have to put in their name, Biographical Info, website and set a password?
Having read this I thought it was rather enlightening.
I appreciate you taking the time and effort to put this article
together. I once again find myself personally spending way
too much time both reading and leaving comments. But so what, it
was still worth it!
Hi, I am able to create custom registration form, and it works well. I do not know how to replace the link ‘register’ to reflect my custom registration form in wordpress login form.
i tried add_filter( ‘register’, ‘my_register_link’ );function my_register_link ( $orignal_link ) {return home_url(‘/register.php’);
}
It still shows …/wp-login.php?action=register than …/myregister.php.
Please help i have a parse error on line 86. what should i do?
Thank you in advance