How To Use the Content Control Shortcode

Updated on March 1, 2024

What’s in This Guide

This guide is all about the Content Control shortcode. Below is a quick peek of what the shortcode looks like.

[content_control]Your restricted content goes here ;-)[/content_control]

We’ll give you a list of the Content Control version 2 shortcode parameters and share examples of how to use them.

Let’s dive in!

List of Parameters

All parameters are optional. If you add a parameter, be sure it’s followed by an equal (=) sign and the values of your parameters are inside double quotes (“”). E.g., allowed_roles=”subscriber”.

  • status: Use status=”logged_in” to allow only logged-in visitors to see the content in between the shortcode tags. logged_in is the default. So, if you leave out this parameter, only logged-in visitors can see your content. Use status=”logged_out” to allow only logged-out visitors to view your content.
  • allowed_roles: If left out, all roles can view your content (the default). Add one (or more) roles to narrow down which role(s) can see your content. If you add more than 1 role, separate each role with a comma (,). E.g., allowed_roles=”administrator,subscriber”.
  • excluded_roles: Add specific roles you want to block from accessing your content. For example, excluded_roles=”subscriber”, would allow all logged-in visitors except subscribers to view your content.
  • message: Supply a custom denial message if you want to override the default message from the plugin settings. E.g., message=”Dang! You need to log in to see this content.”.
  • class: Add the name of your custom CSS class if you want to use custom styles for your restricted content. E.g., class=”my-cool-style”.

Deprecated Parameters

These version 1.0 parameters still work in version 2.0, but they’ll eventually go away. Please use their replacements to keep your protections working with upcoming releases.

Next, let’s take a look at Content Control shortcode examples.

The Content Control Shortcode

Here are Content Control shortcode examples and summaries of what they do.

1. No Parameters (minimalist)

[content_control]Logged in content[/content_control]

All logged-in roles will see the “Logged in content” text. This shortcode will show the default denial message for anyone not logged in.

2. status Parameter

[content_control status="logged_in"]Logged in content[/content_control]

Same as the no parameters example because status=”logged_in” is the default.

[content_control status="logged_out"]Logged out content[/content_control]

Use this when you want only logged-out visitors to see your content.

3. allowed_roles Parameter

[content_control allowed_roles="subscriber"]Logged in content[/content_control]

Only logged-in subscribers will see the “Logged in content” text. This shortcode will show the default denial message for anyone not logged in as a subscriber.

4. excluded_roles Parameter

[content_control excluded_roles="subscriber"]Logged in content[/content_control]

All logged-in roles except subscribers will see the “Logged in content” text. This shortcode will show the default denial message for logged-in subscribers and logged-out visitors.

5. allowed_roles and status Parameters

[content_control allowed_roles="subscriber" status="logged_in"]Logged in content[/content_control]

The example above means you must log in as a subscriber to see the content protected by this shortcode. The shortcode above does the same thing as example 3 because status=”logged_in” is the default.

Adding the status=”logged_in” parameter is totally optional if you’re restricting content to logged-in visitors. But it’s a nicer and more clear way to see what your shortcode will do (at a glance).

6. allowed_roles Parameter With Multiple Roles

[content_control allowed_roles="subscriber,editor"]Logged in content[/content_control]

Logged-in subscribers and editors will see the “Logged in content” text. This shortcode will show the default denial message for anyone not logged in as a subscriber or editor.

7. allowed_roles and message Parameters

[content_control allowed_roles="subscriber,editor" message="You don’t have access to this."]Logged in content[/content_control]

Logged-in subscribers and editors will see the “Logged in content” text. Anyone not logged in as a subscriber or editor will see “You don’t have access to this.”.

8. class and message Parameters

[content_control allowed_roles="subscriber,editor" class="custom-css-class" message="You don’t have access to this."]Logged in content[/content_control]

Same as example #7 above except the protected content and denial message will have the styles you define in the custom-css-class CSS class.

For example. If you have this custom CSS on your site.

.custom-css-class {
	color: firebrick;
	font-size: 2rem;
}

Then, your denial message and logged-in content will be firebrick red and twice as big as your normal text.

Sorta like this.

Content Control adds the class you put in the class parameter to its list of default CSS classes.

Default CSS Classes

When you can view the content (allowed access), here are the default CSS classes in the div tag that wraps your protected content.

  • content-control-container
  • jp-cc
  • content-control-accessible
  • jp-cc-accessible

When you cannot view the content (denied access) you’ll see these classes in the div tag.

  • content-control-container
  • jp-cc
  • content-control-not-accessible
  • jp-cc-not-accessible

9. Wrapped Around HTML Content and HTML in the Denial Message

[content_control allowed_roles="administrator,subscriber" message="Sorry. You need to log in as a <strong>subscriber</strong> or <strong>admin</strong> to see this part of the content."]

<em>
Tempor ipsum bicycle rights, ut artisan poutine viral small batch slow-carb kitsch freegan cred dreamcatcher direct trade id. Kinfolk poke sed, portland cred succulents shaman wayfarers laboris tbh before they sold out live-edge.
</em>

[/content_control]

If you’re not logged in as an administrator or subscriber, you’ll see the denial message with the words subscriber and admin in boldface.

If you are logged in as an administrator or subscriber, you’ll see the protected content in italics.

Here’s a live example using the exact shortcode above (i.e., we copied and pasted that shortcode right under this paragraph).

Is this article helpful? What are your feelings