How To Restrict Access To Areas Of Your WordPress Website
Back in May we wrote a blog post about the various ways to use WordPress and some plugins to restrict access to your website. These solutions applied to whether it was only certain sections or the entire site. Today I’ll expand on Kevin’s post and show you how the restricting access idea works and how you can use it with one of our themes. I’ll also touch on how to use our protected shortcode which comes bundled in all our themes.
Reasons To Restrict Access To Your Website
There are many reasons you may decide to restrict some content on your website from being viewed by the public. Whether it is to have user accounts, content for sale, or confidential data, you can use this method to house all your content in one place, thus allowing you to grant permission to those you choose to view it.
Top reasons to restrict access to a particular website might include:
- User Accounts
- Confidential Data
- Personal Data
- Digital Goods For Sale ( Books, Tutorials, Movies, Music)
- Pro Rated Services
- Pro Rated Media
- Addons
An example of restricted access is lynda.com.
Users visit the website to find video based courses to browse through and decide if they want to buy a plan. You can Become a Member by clicking in the top right side of the header area or by clicking the big call-to-action button on the homepage like you see above. From there, users are presented with a tier of plans to select from. Upon selecting a tier some information is gathered and your account is created. After your account has been saved you get access to the restricted area of the website. This area contains the library of media lynda offers to its paid users.
Adding the same functionality is entirely possible with a WordPress website. Luckily some amazing developers out there have created some WordPress plugins to make matters easier when implementing such a nice feature.
Adding Restricted Sections With a Plugin
Download the Restrict Content Plugin
I’ll be using the Restrict Content plugin by pippinsplugins to get things started off. Head to your WordPress Admin area and add the plugin. I searched Restrict Content and it was the first plugin on the list. Download it and activate it.
Next head to the Settings area in the left navigation. Look for the newly added link titled Restrict Content. You should see a screen similar to this:

Settings / Restrict Content
Inside the Restrict Content Settings panel are input fields where you can enter in message which displays if users try to access areas in which they are not allowed.
If you’re following along, enter the message below:
- Restricted Message – We’re sorry. You do not have permission to access this page. Please sign up to be granted access.
- All the rest – Just add the same message above for each tier of user role.
If you plan on having multiple user roles on your site, feel free to fill these in where needed.
Create Restricted Content
Lets create a page that will have some content we don’t want to be accessible unless it’s for users with accounts on our site. I’ll call the page Books.
The intent would be to have books available for download to those with access to the page. The books will be digital downloads that are free for those who have been granted permission.
With the Books page created, I’ll add the content below. Navigate to the new page and notice the new block below the text area titled Restrict this content.

The Restrict Content plugin adds this extra section within our pages.
Here you can control who gets access to the page. I’ve set it to allow subscribers to see the page. Once someone subscribes to the website they will get access to the free books. This in return gets your users to contribute their emails to be setup with a newsletter or form of contact. So out of the transaction you get their attention and they get your free content so long as they subscribe.
Inside the page I’ll add some sample content and books for download. (Keep in mind, this is an example so the books are not actually available for download.) I have used our Page builder to create 3 block items and a fullwidth header for this specific page which turned out like below. Style yours however you like. The page builder makes it easy!

Our “restricted” page all set up.
Now that we have our restricted page setup we need to make sure we can’t access it. At the moment I am an administrator, which means I have access. Look what happens when I log out and try to access the page.

The page becomes restricted because only logged in users can access it.
Now obviously we need some better styling, but when I visit the url in my browser to my site, I can’t access the content I could before when I was logged in. I’ll leave the CSS styling as a exercise for you if you are following along.
Also at the moment our signup link is broken. We need to link it to where users can sign up as subscribers to our website to get access to the books page.
Allowing Registration
By default WordPress prohibits users from subscribing. You can enable this feature by going into your admin area and navigating to Settings / General.
Look for the Membership and New User Default Role

To allow for users to register you need to enable the membership setting.
Check Anyone can register and leave the New User Default Role to Subscriber.
Now if you navigate to your sites admin URL which would look like this:
https://mywebsite.com/wp-admin/
You should now see a Register link below the familiar login form. Pretty cool right?

A new register link appears below the familiar WordPress login form.
Example Registration
To really prove that our restricted content works, lets create a new sample user.
Enter a new username and email not already in use. A temporary password will be emailed to you, which you can change upon logging in. Be sure to do this for security sake.
Now login with the new credentials as the sample user. You will be acting as only a subscriber at this point so you can’t edit anything on the website but you should now be able to see the Books page with no issues. Yes! It works!

As a new subscriber, I have logged in and can now access the “Books” page we restricted access to. You need an account on the website to access this page.
The Elegant Themes “Protected” Shortcode
Now that I went though all the trouble to show you how to do this with a third party plugin, I’ll fill you in on an awesome feature included with our own themes.
Behold the Protected shortcode. Simply enter content you want to be private in between the short codes like so:
[protected]My protected content![/protected]
For a quick example I created a new page called Protected and added a button using our shortcode in between the protected short codes I just mentioned. All together the content looks like this:
[protected]
[button type=”big”] Sign Up [/button]
[/protected]
Nothing too special but more than enough to illustrate the nice feature.
Since I am logged in our button displays on the page when we visit it.

The content we are protecting with the built in “protected” shortcode.
But not if I log out you will see a form in the contents place as it is “protected” from view from the public eye. This is a great feature to use for data, digital goods, or more in which you would like to only give access to certain users.

If the user is logged out they are presented with a form to log in. If they have an account they can log in to view the content.
Conclusion
Granting access to users of your site seems like a daunting process at first but with the massive WordPress community combined with our great theme additions you can really take your website to the next level. Restrict access is great for people looking to make some income online, in fact it’s how most commerce or product based websites operate.
Do you currently restrict access to parts of your website? Tells us your ideas and methods in doing so in the comments!
feature image via shutterstock author Best3d
The post How To Restrict Access To Areas Of Your WordPress Website appeared first on Elegant Themes Blog.
Comments
How To Restrict Access To Areas Of Your WordPress Website — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>