Skip to content

Restrict Content Shortcodes

The Restrict Content Addon’s shortcode restricts part of a page or post: whatever sits between its opening and closing tags is shown only to users who meet the shortcode’s conditions. This article covers the access level shortcode you copy from the settings page and the attributes for other conditions.

You need the Restrict Content Addon installed and active, which requires the Plus or Elite plan, and at least one access level; see Managing access levels. To restrict a whole page or post, use its Restrict content panel instead; see Restrict WordPress Pages & Posts.

Using a shortcode to restrict content

  1. In your WordPress dashboard, go to Automator > Settings > Addons > Restrict content.
  2. In the Access levels table, copy the level’s code from the Shortcode column.

The Access levels table with the Shortcode column for each access level

  1. Paste the shortcode into the page or post where the restricted content belongs.
  2. Replace Content to show with the content you want to protect, and update the page.

The shortcode you copy looks like this:

[automator_rc access_level="uarc_gold"]Content to show[/automator_rc]

It has three parts:

  • The opening tag, automator_rc with access_level="uarc_gold", restricts what follows to users in the access level whose slug is uarc_gold.
  • Content to show is the placeholder for what you want to protect: text, a video, another shortcode, or anything else a page can hold.
  • The closing tag, [/automator_rc], marks where the protected content ends.

Users in the level see the content. Everyone else, including visitors who are not logged in, sees nothing in its place, unless you add a restriction message (see below). Administrators always see the content, so check the page while logged in as another user.

Advanced shortcode attributes

The copied shortcode covers most needs. For other cases, use these attributes, alone or together. When a shortcode has more than one condition, a user must meet all of them to see the content.

Attribute Shows the content to
access_level="slug" Users in the access level. Separate several slugs with commas to allow users in any of those levels.
access_level_not="slug" Logged-in users who are not in the access level; the opposite of access_level. With several slugs separated by commas, the user must be in none of them.
user_field="meta_key" with user_field_value="value" Users whose custom user field holds that value. Requires the Custom User Fields Addon. user_field takes the field’s meta key, shown under the field’s name at Automator > Settings > Addons > Custom user fields.
user_field="meta_key" with user_field_value_not="value" Users whose custom user field does not hold that value.
restriction_message="text" Not a condition: the text shown in place of the content to users who do not meet the conditions. Without it, they see nothing.

For example, if a custom user field named Country has the meta key uacuf_country, this shortcode shows its content only to users whose Country is Canada:

[automator_rc user_field="uacuf_country" user_field_value="Canada"]Content to show[/automator_rc]

This one shows an upgrade offer to every logged-in user who is not already in the Gold level:

[automator_rc access_level_not="uarc_gold"]Upgrade to Gold today.[/automator_rc]

And this one shows the content to members of either of two levels, with a message for everyone else:

[automator_rc access_level="uarc_gold,uarc_silver" restriction_message="This content is for Gold and Silver members."]Content to show[/automator_rc]

With no attributes at all, the shortcode shows its content to every logged-in user and hides it from visitors who are not logged in:

[automator_rc]Content for logged-in users[/automator_rc]

Things to know

  • Check slugs carefully. A slug that matches no access level, because of a typo or because the level was renamed or deleted, counts as met, so the content is shown to every logged-in user.
  • Shortcodes have their own message. The Access restriction message on the settings page is used for restricted pages and posts, not for shortcodes; use restriction_message for those.
  • Blocks can be restricted without shortcodes. In the block editor, a block’s own settings can restrict it; see Restrict Content for Blocks.

Related: Managing access levels, Restrict WordPress Pages & Posts, Restrict Content for Blocks, Managing custom user fields.

Comments (0)

Leave a Reply

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

Back To Top