WordPress Content Restriction Shortcodes - ProfilePress

WordPress Content Restriction Shortcodes

The Content Restriction shortcodes let you restrict access to some or all of your WordPress content to users based on their user roles, usernames/email addresses, or logged-in status.

You can restrict access to certain parts of your (posts, pages, custom post types) content using our restrict-content shortcodes.

Restrict Content Shortcode

ProfilePress provides the shortcode [pp-restrict-content]protected content...[/pp-restrict-content] to hide or show content to specific WordPress users.

The shortcode accepts the following attributes listed.

Attribute Description
roles Specify the user roles. Separate multiple roles with a comma.
users Specify the user ID, usernames, and/or email addresses of users.
action Determines whether to hide or show the restricted content. Accepts hide or show as a value. Default is show if not specified.

Restrict Content to Specific User Roles

The shortcode below will restrict content (show content) to users with the author role.

[pp-restrict-content roles="author"] content here [/pp-restrict-content]

To restrict content to users of specific roles, separate the roles with a comma.

[pp-restrict-content roles="author, editor"] content here [/pp-restrict-content]

 

Restrict Content to Specific Users

The shortcode can also restrict content to specific users using their user IDs, usernames, or email addresses.

[pp-restrict-content users="johndoe, sandra, [email protected], 12"] content here [/pp-restrict-content]

 

Hiding Restricted Content from Matched Users

By default, the shortcode will only show or display the restricted content to users that match the specified restriction rule.

The shortcode below hides content from users with the “author” role and the user with “[email protected]” as their account email address and the user with ID “20”.

[pp-restrict-content roles="author" users="[email protected], 20" action="hide"] content here [/pp-restrict-content]

 

Hiding Contents from Logged-Out/Guest Users

When you want to show content or restrict content to only users that are logged in, wrap the content with the following shortcode:

[pp-logged-users]content to hide here[/pp-logged-users]

This will hide the content from all users that are NOT logged in. Only users that are logged in will see the content.

Hiding Content From Logged-in Users

When you want to show content or restrict content to only users that are logged out, wrap the content with the following shortcode:

[pp-non-logged-users]content to hide here[/pp-non-logged-users]

This will hide the content from all users that are logged in. Only users that are not logged in will see the content.

 

Protecting your partial content in the Gutenberg editor

When using the new Gutenberg (Block) editor, the procedure of protecting your content is similar. The only difference is that in the Gutenberg editor you need to wrap your content between two shortcode blocks.

You can do this in these simple steps.

Step One: Insert the shortcode block at the beginning of the content you intend to lock.

Step Two: Input the opening part of the content protection shortcode in the field

Step Three: Insert another shortcode at the end of the content you intend to lock.

After publishing your post, all unauthorized visitors will not see the content you protected.

That’s all.