How To Add a Restriction to a Block

Updated on February 15, 2024

What’s in This Guide

In this how-to guide, you’ll create a restriction for a WordPress editor block in a post or page.

You’ll learn how to:

Do you need to restrict entire posts or pages instead of protecting a block?
If you need to restrict posts, pages, archives, and more, head over to our A Quick Start to Your First Global Restriction guide.

Turning On Content Controls for a Block

1. Edit a post or page in Gutenberg (WordPress block editor)

Log into your WordPress admin and edit a post or page. Make sure you’ve got the WordPress block editor turned on.

2. Add a block or select an existing block

Add a new block or click an existing one. In the screen capture below, we clicked on the paragraph block that starts with “Welcome to WordPress.”

Selecting a Paragraph block in Gutenberg

3. Click Enable Controls for your block

While your block is still selected, click Enable Controls under Block Controls in the block settings sidebar.

Content Control v2 block controls

Two things happen when you enable controls

  1. A section for Device Rules appears. All devices (desktop, tablet, and mobile) are on by default. Anyone who is allowed to view your block can see it on any device.
  2. A section for User Rules appears. All logged-in visitors can see your block by default. Anyone logged out cannot.

You can expand each section to change which devices your block shows and which user roles can see it. That’s coming up next.

Heads up!
You must expand the User Rules to protect your block. You’ll see a crossed-out red-eye icon next to the block right after you expand User Rules. That lets you know Content Control is now restricting your block so only logged-in visitors (the default is any role) can view it. You can accept that default or change the rule to what you need.

A Simple Example

Let’s walk through an example where we change device and user rules. Say we have the following:

  1. A special mobile app exclusively for our subscribers.
  2. A download form that subscribers must submit to get our app.

Our goal: We want to display our download form to logged-in subscribers while they’re on their mobile phones.

Here’s how we can do that.

Working With Device Rules

1. Edit a post or page

Remember to use the block editor.

2. Add a form

You can use any block for our example scenario if you don’t have a form.

3. Click Enable Controls

4. Click the plus (+) icon next to Device Rules

5. Click the toggle button next to TABLET and DESKTOP to turn them off

Keep the MOBILE toggle on.

6. Save your changes

Click Publish or Update for your post or page.

Now, all logged-in users can see your form only on mobile devices.

Next, let’s add a user rule to let only subscribers see the form instead of all roles.

Working With User Rules

1. Click the plus (+) icon next to User Rules

2. Select Matching for the USER ROLE field

Leave the WHO CAN SEE THIS CONTENT? field set to Logged In Users.

3. Choose subscriber for CHOSEN ROLES

4. Click Update to save your changes

Before You Go

So now, you’ll see your block if you’re logged in as a subscriber on a mobile phone.

If you’re not logged in as a subscriber and not using a mobile phone, your block won’t display. It’s protected!

Pro tip: Always make sure to clear all caches on the browser, WordPress, server, and CDN before testing any changes.

Is this article helpful? What are your feelings