Shortcodes

Restricting a whole page is often too blunt an instrument — sometimes you want everyone to see the introduction while only members read the rest. That is exactly what the content restriction shortcodes in Restrict for WordPress are for. This guide explains how the Shortcodes area of the plugin generates ready-to-use shortcodes, how the shortcode structure works, and how to show a custom message to visitors who don’t meet your criteria.

What the Shortcodes area does

The Shortcodes area of Restrict is used to generate shortcodes which can then be used to restrict content partially on a page or post. You don’t have to memorize any syntax — the plugin builds the shortcode for you based on your selections, and you simply copy and paste it where you need it.

Shortcodes area of Restrict for WordPress with generators for logged-in, logged-out, role and capability based shortcodes

From top to bottom, you will find the following areas:

  • Content available to logged in users – generates the shortcode for restricting part of the content so it is visible to logged-in users only.
  • Content available to logged out users – generates the shortcode for restricting part of the content so it is visible to logged-out users. This one is great for showing sign-up prompts or teasers only to visitors who haven’t logged in yet.
  • Content available to users with specific role – generates the shortcode for restricting part of the content so it is visible to users with a specific WordPress user role. All the existing user roles will be listed, so just click the user roles you want and the shortcode will be automatically generated based on your selection.
  • Content available to users with specific capability – generates the shortcode for restricting part of the content so it is visible to users with a specific user capability. The difference here is that capabilities won’t be listed; instead, you will need to manually enter the user capability, and the shortcode will be automatically created based on your entry.

How to use a generated shortcode

Regardless of which criteria you elect to use, the usage of the shortcode is the same:

  1. Copy the generated shortcode by clicking the Copy button.
  2. Paste the shortcode into the page or post where you want to use it.
  3. Place the content you want to restrict between the opening and closing parts of the shortcode.

The shortcode itself will be in a format similar to this:

[rsc_restrict_content allowed_to="role" user_role="administrator"]Your content here[/rsc_restrict_content]

Understanding the shortcode structure

It is important to understand that this shortcode actually consists of three equally important parts:

  • The opening part[rsc_restrict_content allowed_to="role" user_role="administrator"] — which defines the restriction criteria.
  • The contentYour content here — which is the actual content you will be restricting. Replace it with your real text, images, or other content.
  • The closing part[/rsc_restrict_content] — which goes at the end of the content you want to restrict.

Depending on which criteria you have chosen for the restriction, the opening part of the shortcode will differ, while the closing part is the same for every criteria. If the closing part is missing, WordPress cannot tell where the restricted section ends — so always keep the pair intact.

Custom message

You can also add a custom message for visitors who do not meet the required criteria for the restricted content — for example, a note telling them to log in or purchase access. To display a custom message, include it as the argument protected_message="YOUR MESSAGE HERE" in the opening part of the shortcode. As an example, your shortcode will then look something like this:

[rsc_restrict_content allowed_to="role" user_role="administrator" protected_message="YOUR MESSAGE HERE"]Restricted content goes here[/rsc_restrict_content]

If you don’t add a protected_message argument, ineligible visitors simply won’t see the restricted section. Site-wide restriction messages for fully restricted pages are configured separately in the General settings.

Integrations

If you have WooCommerce installed and activated on your website, you will have an option to restrict content based on WooCommerce-specific criteria, as described in the WooCommerce integration documentation.

Similarly, if you are using the Tickera event ticketing plugin on your website, another area will appear here, allowing you to use Tickera-specific criteria for content restriction. More about this feature can be found in the Tickera integration documentation.

Also, if you are using the Easy Digital Downloads plugin, another area will be available where you can set Easy Digital Downloads-specific criteria. To find out more, check the Easy Digital Downloads integration documentation.

Related documentation