How to restrict the entire WordPress site by excluding a few essential pages

I think you can guess today’s articles after watching the title and GIFY 😉😀. Yes, in this article I will represent how to restrict your entire WordPress site by excluding a few special pages like Login or Registration.

Use Cases

  1. Imagine you are building a site that would be a membership base. So you don’t want to access your site’s content for all the users. In this case, these tips would be helpful for you.
  2. You are a WP User Frontend Pro user, and you want to combine this feature with your membership site so that the guest users can only access the Login and Registration page.

Desclaimer

On my site, I’m using the WP User Frontend Pro plugin, and I want to restrict my entire site by excluding the Login and my custom Registration page. Please note creating a registration form with WPUF is a pro feature. However, there is also a default registration form with the free version to exclude that page if you are in the free version.

Prerequisite

  1. WP User Frontend Free plugin
  2. WP User Frontend Pro plugin (optional)
  3. Restricted Site Access plugin

Start Cooking

I need this extra third-party plugin (Restricted Site Access) because WPUF Pro doesn’t have the feature to restrict the entire site for the guest users. However, you can restrict pages, posts by the WPUF content restriction feature. But as you know, few special users want to restrict the entire site except a few pages like Login & Registration, and we will cover up that hole.

Process

Install the Restricted Site Access plugin by visiting your wp-admin → Plugins → Add New and search for the plugin

No click on the plugin’s settings or navigate to wp-admin → Settings → Reading to configure the restricted settings.

As you can see, I have define the Login and Registration page link on the Restriction message so that users can access to those page.

Wait! It’s not done yet 😀. The main task is still pending.

We print those two essential pages link on the frontend, but this plugin still does not let the users access those pages. So we have to filter those two pages so that when users are requesting/clicking on those pages, it whitelists those pages.

Final Round

Now, I will inject some custom filter/hook to whitelist those login & registration page to visit.

Visit your theme/child-theme’s functions.php file and open with a text/code editor and add this below code snippets

/**
@ Whitelist Login and Registration page to access by Guest users [For Restricted Site Access Plugin]

**/

add_filter( 'restricted_site_access_is_restricted', function( $is_restricted, $wp ) {
    if( 'simple-registration' === $wp->request ) { //registration page slug
        return false;
    }
    elseif( 'login' === $wp->request ) { //login page slug
        return false;
    }    
    return $is_restricted;
}, 10, 2 );

Great! Now visit your site and click on the register or login page link. You will see it lets you access the registration & login page.

This is pretty simple right? 😎😉

Bonus

Are you still struggling to get it work 😞✋ No worries, I have made a quick video so feel free watch.

Don’t forget to gives a thumbs up and subscribe my channel! 🥂

MM Aurangajeb
MM Aurangajeb

Spreading Happiness. Support Engineer, WordPress Enthusiast, Blogger.

Articles: 18

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.