Purpose

The [protect-content] shortcode can be used to show or hide small sections of content based on role or status.

Usage

It has three parameters:

operation
Whether to show or hide the content if the conditions are met. Valid values: show or hide (default: show)
role
Which role(s) to require or forbid. Valid values: the internal name of any role (e.g. administrator, non-member, etc.), comma-separated if more than one (default: null)
status
Which status to require or forbid. Valid values: logged-in or logged-out (defaults to null)

Examples

Each code example is followed by the actual shortcode, but you’ll only see it if you meet the conditions.

Show content if conditions are met

[protect-content role="editor"]This content is only shown to Administrators and Editors.[/protect-content]
Result
[protect-content role="author"]This content is only shown to Administrators and Authors.[/protect-content]
Result
[protect-content role="contributor"]This content is only shown to Administrators and Contributors.[/protect-content]
Result
[protect-content role="member"]This content is only shown to Administrators and Members.[/protect-content]
Result
[protect-content role="subscriber"]This content is only shown to Administrators and Subscribers.[/protect-content]
Result
[protect-content status="logged-in"]This content is only shown to logged-in users.[/protect-content]
Result

Hide content if conditions are met

[protect-content operation="hide" role="editor"]This content is hidden from Editors.[/protect-content]
Result
This content is hidden from Editors.
[protect-content operation="hide" role="author"]This content is hidden from Authors.[/protect-content]
Result
This content is hidden from Authors.
[protect-content operation="hide" role="contributor"]This content is hidden from Contributors.[/protect-content]
Result
This content is hidden from Contributors.
[protect-content operation="hide" role="members"]This content is hidden from Members.[/protect-content]
Result
This content is hidden from Members.
[protect-content operation="hide" role="subscriber"]This content is hidden from Subscribers.[/protect-content]
Result
This content is hidden from Subscribers.
[protect-content status="logged-out"]This content is only shown to visitors who aren't logged in.[/protect-content]
Result
This content is only shown to visitors who aren’t logged in.
Ad for Tuesday Morning newsletter, links to newsletter sign up

Recent News