Limit access with shortcodes

In addition to being able to restrict whole posts and pages, you can also choose to restrict only select sections of the content.

 

Good to know: As with Access Conditions, administrators are by default able to see all content hidden by restriction shortcodes.

 

Restrict Content Shortcode for Levels

If you have a level with the name “platinum”, you can hide a section for unauthorized users with the following shortcode:

[restrict level="platinum"]

This content can only be seen by members of Platinum level or above.

[/restrict]

 

Likewise, if you want to hide a section for level members, use the following code (notice the !):

[restrict level="!platinum"]

This content can only be seen by users without Platinum level or above.

[/restrict]

 

If you want exclusively show content to multiple levels that do not extend eachother, you can use commas to separate them:

[restrict level="platinum-a,platinum-b"]

This content can only be seen by members of Platinum A or Platinum B level or above.

[/restrict]

 

Important: The level parameter only accepts the level name, not the title or id.

 

Restrict Content Shortcode for User Roles

Restricting content to roles is done in the same manner as levels, but with a “role” parameter instead.

[restrict role="subscriber"]

This content can only be seen by subscribers.

[/restrict]
[restrict role="!subscriber"]

This content can only be seen by users without subscriber role.

[/restrict]
[restrict level="contributor,editor"]

This content can only be seen by contributors and editors.

[/restrict]
Was this article helpful to you?