Looking for an easy way to restrict content based on user role? If you run a community site on top of WordPress which allows user registration, you probably need a simple way to control which users can access certain pages.
In this tutorial, we’ll show you how to easily restrict access to certain WordPress pages by user role using Profile Builder.
You’ll have everything set-up and ready by following the 3 easy steps below:
Enable Content Restriction feature in Profile Builder
To ensure you get access to the Content Restriction feature within Profile Builder you’ll need version 2.6.9 or higher. Next, go to your WordPress Dashboard, download & install Profile Builder or if you’re using an older version, update the plugin to the latest version.
Then, under Profile Builder menu tab, navigate to General Settings and make sure you enable Content Restriction.
Set up Custom Restriction Messages
After activating the restrict content feature, you’ll notice a new submenu item appearing under Profile Builder tab, named Content Restriction.
From here you’ll be able to setup the type of restriction, as well as customize the default restriction messages users will see if they don’t have access to certain content.
You can also choose to display a short preview of the restricted content.
Based on these settings, if a non-logged-in user wants to access the restricted content, he will get a short preview containing the first 20 words or any number set in the settings, similar to the one below.
Restricting a Page, Post or Custom Post Type based on User Role
After setting up the restriction messages, in your WP admin panel simply navigate to each post, page or custom post type you want to restrict. Below the content editor you’ll notice a section called “Profile Builder Content Restriction“.
From here you can set up the type of restriction, select which user roles will have access to the content, as well as add custom restriction messages if required.
In the example below, the post content will be available for all our logged in users that have the user role of “Administrator” or “Author” attributed.
Furthermore, if we want to customize the restriction message for this specific post, we can type in something different than the default ones.
Also, if you want to send your users to another page, you can enable the redirect feature. Inside our post, we will redirect all of the users that don’t have the following roles assigned: Editor, Subscriber, SEO Manager or SEO Editor.
Note: You can replicate the same steps for restricting content based on user role for any other page, post or custom post type on your website.
Restricting Content based on User Role is pretty straight forward using Profile Builder.
You can use it in multiple scenarios, from providing members only content, to restricting access to personal or confidential data, or simply setting a WooCommerce store available to members only.
Are you currently restricting access to parts of your website? Let us know your ideas and methods in doing so in the comments section below.
Subscribe to get early access
to new plugins, discounts and brief updates about what's new with Cozmoslabs!