Restrict part of a page with the shortcode
The [content_gate] shortcode hides part of an otherwise public page. Put the reserved text between [content_gate] and [/content_gate]: visitors who do not match see nothing, or the message you choose.
How to add it
- Open the page for editing.
- In the block editor, add a Shortcode block (click + and search for "Shortcode"). In the classic editor, type directly in the text.
- Type the shortcode with your content in the middle, for example:
[content_gate who="logged_in"]Reserved paragraph.[/content_gate] - Click Update or Publish.
Attributes
| Attribute | Values | Default | What it does |
|---|---|---|---|
who | logged_in, logged_out, roles | logged_in | Who can see the content. |
roles | Role names separated by commas, e.g. editor,author | empty | Used with who="roles". Pro. |
devices | desktop, mobile, or both separated by a comma | empty (every device) | Shows the content only on those devices. Pro. |
message | Any text | empty | What others see. Without it, the content simply disappears for them. |
Examples
- Only for logged in users:
[content_gate who="logged_in"]Reserved paragraph.[/content_gate] - Only for editors and authors (Pro):
[content_gate who="roles" roles="editor,author"]Internal note.[/content_gate] - A sign-up button only for visitors who are not logged in, with a message for everyone else:
[content_gate who="logged_out" message="You already have an account."]Sign up[/content_gate]
Role names
In roles use the role's internal name in lowercase: administrator, editor, author, contributor, subscriber. Roles added by other plugins have their own name (WooCommerce, for example, adds customer).
In the free version
The shortcode works in the free version with logged_in and logged_out. who="roles" is applied as "logged in users" and devices is ignored until a licence is active.
Administrators always see the content between the tags, even with who="logged_out". Check the result in a private browser window.
Write to us and tell us which plugin, what you tried and what you see. We answer from Italy, usually within one working day.