Do you want to show a custom registration page for users in WordPress? If yes, you have landed in the right place. You might enable registration for your users to sign up.
As we know, WordPress has its own default signup form. But it is ugly? Why?
Because it contains WordPress Logo and hasn’t much style, today we will learn how to create one for your own website. Let us get started.
Create a Custom Registration page in WordPress
WordPress comes with lots of plugins which can help you in building a great looking page.
But we don’t prefer over them because they overload the site.
Also, many plugins can help you in dropping your signup page anywhere.
But we will manually create a signup form for our WordPress website. Let’s start.
Step 1 – Navigate to the themes folder
The first is to navigate the themes folder. If you are running a child theme, then navigate to it.
If using only parent theme, then navigate to its folders.
There we will create a file named as,signup.php
inside it, we will add this code.
<?php /* Template Name: Register */ get_header(); // Exit if accessed directly if ( !defined('ABSPATH')) exit; ?> <body id="login-page" <?php body_class(); ?>> <div class="container"> <div class="row register-page-container p-3 p-lg-5 mt-5 d-flex justify-content-center w-75 mx-auto"> <?php global $wpdb, $user_ID; //Check whether the user is already logged in if (!$user_ID) { // Default page shows register form. // To show Login form set query variable action=login $action = (isset($_GET['action']) ) ? $_GET['action'] : 0; // Login Page if ($action === "login") { ?> <?php $login = (isset($_GET['login']) ) ? $_GET['login'] : 0; if ( $login === "failed" ) { echo '<div class="col-12 register-error"><strong>ERROR:</strong> Invalid username and/or password.</div>'; } elseif ( $login === "empty" ) { echo '<div class="col-12 register-error"><strong>ERROR:</strong> Username and/or Password is empty.</div>'; } elseif ( $login === "false" ) { echo '<div class="col-12 register-error"><strong>ERROR:</strong> You are logged out.</div>'; } ?> <div class="col-md-5"> <?php $args = array( 'redirect' => home_url().'/login/', ); wp_login_form($args); ?> <p class="text-center"><a class="mr-2" href="<?php echo wp_registration_url(); ?>">Register Now</a> <span clas="mx-2">·</span><a class="ml-2" href="<?php echo wp_lostpassword_url( ); ?>" title="Lost Password">Lost Password?</a></p> </div> <?php } else { // Register Page ?> <?php if ( $_POST ) { $error = 0; $username = esc_sql($_REQUEST['username']); if ( empty($username) ) { echo '<div class="col-12 register-error">User name should not be empty.</div>'; $error = 1; } $email = esc_sql($_REQUEST['email']); if ( !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email) ) { echo '<div class="col-12 register-error">Please enter a valid email.</div>'; $error = 1; } if ( $error == 0 ) { $random_password = wp_generate_password( 12, false ); $status = wp_create_user( $username, $random_password, $email ); if ( is_wp_error($status) ) { echo '<div class="col-12 register-error">Username already exists. Please try another one.</div>'; } else { $from = get_option('admin_email'); $headers = 'From: '.$from . "\r\n"; $subject = "Registration successful"; $message = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password"; // Email password and other details to the user wp_mail( $email, $subject, $message, $headers ); echo "Please check your email for login details."; $error = 2; // We will check for this variable before showing the sign up form. } } } if ( $error != 2 ) { ?> <?php if(get_option('users_can_register')) { ?> <div class="col-md-5 manual-register-form"> <form action="" method="post"> <p> <label for="user_login">Username</label> <input type="text" name="username" placeholder="Type your Username Here" class="register-input mb-4" value="<?php if( ! empty($username) ) echo $username; ?>" /><br /> </p> <p> <label for="user_email">Email</label> <input type="text" name="email" placeholder="Type your Email Here" class="register-input mb-4" value="<?php if( ! empty($email) ) echo $email; ?>" /> <br /> </p> <input type="submit" id="register-submit-btn" class="mb-4" name="submit" value="SignUp" /> </form> <p>Already have an account? <a href="/login">Login Here</a></p> </div> <?php } else { echo "Registration is currently disabled. Please try again later."; } } ?> <?php } } else { ?> <p>You are logged in. Click <a href="<?php bloginfo('wpurl'); ?>">here to go home</a></p> <?php } ?> </div> </div> <?php get_footer(); ?> </body> </html>
Step 2 – Create a Page in WP Dashboard
Now we will create a page for our registration form. Navigate to Pages>>Add New and name it as Register.
Then we will set it a template Register.
And publish the page. Enjoy using a new signup page for your WordPress powered website.
Add some styling to it and make it more useful and clearer.
I hope you loved our tutorial and if so, please show some love by sharing the tutorial.
Please have your valuable questions and suggestions in the comment box.
Gill Bates says
Hi there, nice tutorial. Please activate Windows.
Raashid Din Dar says
hahaha! Thanks Dear
Riyaz Shaikh says
Hey, Thank you for sharing.
great tutorial, was able to create a Register page using above code. Will update CSS to me it look stunning.
Any tutorial on Log in page?
Regards,
Raashid Din Dar says
Thank You Riyaz for your kind words.
Yes we have a tutorial on login. Please Read this article http://websiteguider.com/create-a-custom-login-page-for-wordpress-without-plugin/
vimal says
thanks for your nice tutorial and let me know i am having this kind of issue Registration is currently disabled. Please try again later.
Raashid Din Dar says
Hi,
You have to enable it from settings.
Go to Settings>>General and check the box “Anyone Can Register”.
Thanks
vimal says
hi
thanks for prompt reply.it’s working fine but it does show username exist already issue even i changed new user too.
Raashid Din Dar says
Will you please share website URL where you are applying the code.
Also, please double check you aren’t using same email and username.
However, the code is working fine. No issue found.
Thanks
vimal says
hi,
thanks again for your prompt and kind info about the issue.now everything is working fine.
Raashid Din Dar says
Great to hear that.
vimal says
Hi,
can you let me know to add the social media with this register panel for logging user via their social media like facebook,gmail
Raashid Din Dar says
You can use social media login with this code using their APIs. It is long process so I can’t share with you in comment section but soon I will write a tutorial on it.
Thanks
vimal says
Hi,
I have another one doubt how to change the wordpress name as my site name in the registeration successfully notification in my mail.
Raashid Din Dar says
Hi,
Please use support section to get answer of all queries.
vimal says
How can i get the support section link?
Raashid Din Dar says
http://websiteguider.com/submit-ticket/
vimal says
thanks for your prompt reply.
Dido says
Hi,
Is it possible to add more fields to the form, it would be nice if subscribers can choose their own password for instance.
Raashid Din Dar says
Hi,
Yes you can easily add more fields to the form easily. You should have some PHP and HTML knowledge.
A says
Hi,
The register seems to be working just fine except for the wp_maill function.
I just copied and pasted your code.
Included my wp-load file as well to make sure.
Raashid Din Dar says
Hi,
I didn’t got you what you are trying to say.
Savan says
How to set custom page redirect url after the registered success?
Raashid Din Dar says
Hi,
You need to tweak this code a little bit.
I will update the tutorial soon to address this problem.
Here is the quick fix to the problem.
Change this code.
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$message = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
// Email password and other details to the user
wp_mail( $email, $subject, $message, $headers );
echo "Please check your email for login details.";
$error = 2; // We will check for this variable before showing the sign up form.
}
with this
$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$message = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
// Email password and other details to the user
wp_mail( $email, $subject, $message, $headers );
echo "Please check your email for login details.";
wp_safe_redirect(admin_url());
exit;
$error = 2; // We will check for this variable before showing the sign up form.
}
Thanks for leaving a valuable comment.
Savan Patel says
Thanks for your prompt reply it’s working.
Thank you again.
Jonathan says
Will theme updates override this file if placed within the parent or child theme folders?
Raashid Din Dar says
Hi,
Yes, Jonathan, if you update the theme, everything is removed in the older version. So it would be best to create this page in child theme. But remember, if you update the child or parent theme, everything will get removed.
Thanks
mayank says
Hi i have use the above code but i am not getting mail after form submisssion please help
Raghav says
How to edit this after add page
Hyacinth Sera says
Hey! I simply wish to give a huge thumbs up for the good info you will have here on this post. I shall be coming back to your blog for more soon.