Last Updated on May 14, 2022 by WP Knowledge Hub
How to Allow Users to Register on Your WordPress Website
Are you looking for a way to allow users to register on your WordPress website? We have two brilliant solutions for you!
You can easily enable user registration in WordPress to allow users to sign-up to your blog, get access to special content, or even become content contributors.
Enabling User Registration in WordPress Settings
WordPress has built-in functionality to allow new users to register themselves. By default, it’s not activated, so in order to turn it on, you need to go to Settings > General >then scroll down to Membership and tick the checkbox that says ‘Anyone can register’ .
It’s important to understand the difference between a subscriber and an administrator. An admin is someone who has total control over the site, so make sure NEVER to set “Administrator” as the default user role.
Once you’ve activated this setting, your WordPress website is now open to new user registrations. If you go to the default WordPress login page, you’ll see an option to register now.
Creating a Login and Registration Page
Although users can technically use the default WordPress login page to register now, this poses a bit of an issue:
A) You don’t want users to have to manually type in /wp-admin at the end of your URL to register. This is bad user experience (UX).
B) The WordPress default login/register form is not very pretty, and looks the same on every WordPress website, and that takes away from your theme’s branding.
Before allowing anyone to register on your WordPress website, you’ll want to create a custom login and registration page. But how do you do that?
Well, there are two ways. Using a plugin, or creating them yourself writing a bit of code in the functions.php file.
Using the Theme My Login Plugin
The Theme My Login plugin is one of the, if not the most popular custom login and registration solution available for in the WordPress free plugin repository.
Simply go to Plugins > Add New > and search for Theme My Login, and choose the one with the little chameleon logo. Install it and Activate it and you will notice the new Theme My Login tab in your WordPress dashboard sidebar.
When you click on it, you’ll want to allow users to set their own passwords, and you’ll want to take note of the slugs (URLs) of each important auto-generated plugin page:
Simply add /login/ or /register/ at the end of your URL to test the new page’s functionality.
Once everything is working correctly, you can go to Appearance > Menus > your primary menu, and add the necessary page to your navigation structure to allow users to access the pages directly.
Using the Functions.php to Create a Custom Login and Registration
If you’re more of a hands-on person and you want to practice your coding skills, this alternative is for you. You can replicate the WordPress login form with a function and a shortcode.
Before WordPress introduced the wp_login_form() function, creating a login form on a page was a long and hard process.
Since then, this function allows you to easily display the WordPress login form on any page or post.
The first thing you’ll need to do is access your functions.php file, either through the WordPress dashboard by going to Appearance > Theme File Editor > functions.php, or using an FTP client, like FileZilla.
It’s safer to use an FTP client, because screwing up the functions.php file will cause your website to crash, and if that happens, you need a way to restore the old version of the functions.php file. So, having a backup on your local computer definitely helps!
Creating Your Login Form Shortcode
Once you have the functions.php file open, you’ll want to add this code:
add_action( 'init', 'my_add_shortcodes' );
function my_add_shortcodes() {
add_shortcode( 'my-login-form', 'my_login_form_shortcode' );
}
The code above creates the function that creates the shortcode. Next you’ll want to verify that the user is not already logged in before it calls the wp_login_form() function:
function my_login_form_shortcode() {
if ( is_user_logged_in() )
return '';
return wp_login_form( array( 'echo' => false ) );
}
After adding these lines to the functions.php, you can safely add the new shortcode below to any page or post:
[my-login-form]
Is Opening the WordPress Registration to Anyone Safe?
Before you commit to opening WordPress’ registration to anyone, you should know there are some risks involved. You will be opening the door to countless spammers who will make your life hell unless you deal with the problem beforehand.
You will want to add a CAPTCHA to your registration form, or add the appropriate anti-spam plugin before you do!
That’s it!