Do you want to create a custom registration or sign up form in WordPress without using a single plugin? Then this is the fantastic place for you. Where we have posted the guide and some codes that will help you to make a custom registration form.
How We are Going to Build Registration Form
Let me tell you the secret that with we build Custom Registration Form for our client website. And that what we have shared the guide of creating a registration form. Let’s know how you can build a registration form.
First, create a template file that will contain the below code snippets. Creating template file in WordPress has greater advantages such as give any name to file, apply the template to multiple pages, simple to create.
Below we have posted the code snippets that will help you to make a Registration form easily and stress-free. We have arranged the code snippets separately and explained the code, and what that code have the power to do.
Lastly, we have combined all code into a single file. So you guys will put the whole code into the single file and not need to think or worry where the above code save or below code save.
Let’s get started.
How to Create Registration Form in WordPress Without Plugin
For successfully creating registration form follow the below steps and you will create your first WordPress registration form.
Where to Save Below Codes
All the codes that we’ve posted below will save into your WordPress Theme or your Child Theme folder. Create a file name registration-template.php and copy the codes and paste inside in this file.
Syntax
In this guide, We have used wp_insert_user() function to insert a user into the database, this functions can update a current user or insert a new user based on whether the user’s ID is present.
PHP code
This contains PHP script to validate and accept posted data from our HTML form.
Let’s take a deeper look at the functions that we have used in our code and what those codes can use for.
- email_exists: To look if the user email already exists.
- apply_filters: Calls filters for most of the $userdata fields with the prefix ‘pre_user’, where $userdata is the data contain to create the user.
- do_action: Calls ‘user_register’ hook when creating a new user giving the user’s ID.
HTML code
I’ve added one hidden field to validate if the submitted form is for registration.
Parameters
$userdata
An array of user data.
Complete Source Code
Below is the complete custom registration page source code, copy and paste the snippet below to test it yourself.
The detailed basic tutorial on how to create custom page template can be found at WP Codex.
That’s it!
If you guys love this tutorial and if it helped you leave a comment at least say Thanks. Or if you have any issue go first with the website.
How can I redirect the user to the dashboard area or myaccount area instead of showing that $success message?
for that:
You just need to replace
$success
withwp_redirect( home_url() . '/wp-admin/' );
and it will do that job for you to redirect to the dashboard.
Please where will The users see the Login and register page?. How can I redirect users to front end user profile.
I have pasted your code on my wordpress page but it did not working it shows error . Could you help me how i change code setting.
ss