Do you need to create a WordPress membership site and sell your paid content, such as online services or courses? In this article, we’re going to show you how to change your WordPress website into an online community, school or store with restricted content without any plugin.
Watch this video on WordPress membership site
Running your business on WordPress
WordPress is the most popular content management system (CMS) in the world. Did you know WordPress is powering more than 43% of all websites on the internet? This is largely because creating a professional website and blogging on WordPress are quite easy and enjoyable. WordPress.org has a large active community to exchange almost any question and answer to improve the quality and functionality of your website.
On the other hand, WordPress on wordpress.org is a free and open source CMS, which gives you almost complete freedom and flexibility to develop and design your website the way you dream about it. It is important to note that wordpress.org and wordpress.com are not interchangeable as the latter is actually a WordPress hosting provider founded and maintained by Automattic Company and Matthew Mullenweg, who is the founder of WordPress.
Why do you need a WordPress membership site?
Any WordPress website could become an online business center, namely a school, university, institute, store, etc. with restricted content only for registered members. Creating a membership website on WordPress is an exciting endeavor as it can bring you recurring revenues when your website users turn into monthly subscribers or members who are ready to pay for your services, online courses or products on a monthly basis.
Create a WordPress membership site without any plugin
There are many WordPress plugins that can add membership functionality to your website. However, the majority of these plugins could make your website heavily bloated by adding so much JavaScript to it. Therefore, the best practice is to use the minimum number of plugins installed and activated on your website.
In addition, the best WordPress membership plugins are premium ones, and generally their costs are even much more expensive than greatest WordPress hosting plans. However, we’ve tested the following 2 WordPress plugins to create a membership website for free with satisfactory results:
At LELB Society, which is a bilingual academy of English and Persian or Farsi with 143 active members so far (February of 2023), Dr. Mohammad Hossein Hariri Asl, the founder and website developer of LELB Society on WordPress, has added membership functionality to LELB Society in the following steps.
Updating your functions.php file
As an admin, navigate to your WordPress dashboard area, and then go to Appearance, Theme File Editor, Theme Functions or functions.php. Then add the following code snippet to the end of your functions.php file, and update it. Please note that these files are so sensitive and the slightest imperfections in their codes might lead to fatal or critical errors in your WordPress website. Therefore, you’re strongly advised to create a backup of your website before making any changes to your theme files.
function my_force_login() {
global $post;
if (!is_user_logged_in()) {
auth_redirect();
}
}
The above code snippet in your functions.php file will force any user to login to your WordPress website to be able to access the content. In other words, this simple and short code snippet can easily create a WordPress membership site for you.
In the next stage, you need to add another simple line of code to any custom post type on your WordPress website that you like to be exclusively accessible to your logged-in members. For instance, at LELB Society on WordPress, we’ve developed over 4,100 English and Persian lessons with videos as restricted content only available to our registered members and students.
To create these premium lessons or courses at LELB Society, we’ve been using posts as the main custom post type on WordPress. In fact, all posts or lessons at LELB Society are restricted content that is only available to our registered members on free trial. For this reason, we’ve added the following line of code to the very beginning of our content-single.php file, which creates the template of WordPress posts.
<?php my_force_login(); ?>
We’re using the GeneratePress WordPress theme in which the theme or template file name for posts is content-single.php. Depending on your installed theme, the name of this file might be slightly different. You can also put the above code at the very beginning of your page.php file if you want to restrict your pages, as well. However, at LELB Society, only posts as lessons are restricted content.
Redirecting users to WordPress login page
The 2 code snippets presented in this article will redirect any logged-out user to the WordPress login page and force them to login first in order to access the restricted content on your website. To provide a better User Experience (UX) for your users or members, you’re advised to add social login functionality to your WordPress website.
Add social login to your WordPress website
Social login is much easier compared to traditional long with username and password. Your users can login to their accounts on your WordPress website by using their social accounts, namely Google, Facebook, Twitter, etc. with just one single click. At LELB Society, we’re using the NextEnd Social Login and Register WordPress plugin to facilitate the process of logging and registration.
We’re also using another popular WordPress plugin to improve the security of our WordPress website. This plugin is All-In-One Security (AIOS) – Security and Firewall, which can help you achieve the following 2 important results as the owner of a WordPress membership site:
- Manually approving new registrations compatible with NextEnd Social Login and Registration plugin
- Changing the URL of the default WordPress login page to add another layer of security to your website, which is www.example.com/wp-login.php.
Set a new login page on WordPress
As mentioned earlier, if you follow the steps explained in this article correctly, your logged-out users will be redirected to the WordPress login page to access the restricted content. The problem with this method is that the default WordPress login page cannot be optimized properly as many CSS and JavaScript files must be loaded.
For this reason, you can easily change the default WordPress page with a big WordPress icon on top to any page on your website with the following code snippet that should be added to your functions.php file. Make sure to change the value in: home_url( ‘/login/’ ) in red on line 3 to any slug on your website that you want your logged-out users to be redirected to in order to sign in to your website. In our case, that would be https://www.lelb.net/login/.
add_filter( 'login_url', 'new_login_page', 10, 3 );
function new_login_page( $login_url, $redirect, $force_reauth ) {
$login_page = home_url( '/login/' ); //use the slug of your custom login page.
return add_query_arg( 'redirect_to', $redirect, $login_page );
}
Then if you’re using the NextEnd Social Login and Registration plugin, simply add the following shortcode to embed social login to your new login page:
[nextend_social_login]
How to block registered members?
Sometimes, for any reason, you might want to block a registered member from your website. The easiest way to restrict a registered user’s access to your premium or paid content is to delete that user from the users page in your WordPress dashboard area. However, this is not the best solution because all that user’s information on your website could be deleted. On the other hand, the deleted user might try to register again on your website as a new user.
The best solution to blocking a user on your WordPress membership site is to download and install the User Blocker WordPress plugin. In this way, when a blocked user attempts to login to your website, they will see an error with a customizable message.