Including / Excluding Post Types for Content Restriction

By default, the Restrict for WordPress plugin offers content restriction on posts, pages and eligible custom post types — but not necessarily on every post type that themes and plugins register on your site. This guide shows you how to enable content restriction for a custom post type that is missing the restriction option, and how to exclude a post type you don’t want Restrict to handle. Both changes take a single, short PHP snippet, and full copy-paste examples are provided below.

Before you begin

  • You will need the slug of the post type you want to include or exclude (for example portfolio or event). The plugin or theme that registers the post type usually documents this, and it typically appears in the URL when you browse that post type in the WordPress admin.
  • You need a place to put the snippet. You can add it to your theme’s functions.php file, or you can install a plugin such as Code Snippets and add it there. The Code Snippets approach has a practical advantage: your change survives theme updates and theme switches. If you edit functions.php directly, use a child theme so a theme update doesn’t wipe out your snippet.

Enabling a custom post type for content restriction

It might happen that a certain post type on your website does not have an option for content restriction. If that occurs, you can enable content restriction for that post type by using the simple snippet below, which hooks into the plugin’s rsc_allowed_post_types filter:

function add_specific_post_type($post_types){
$post_types[] = 'my_custom_post_type';
return $post_types;
}

add_filter('rsc_allowed_post_types', 'add_specific_post_type', 10, 1);

Of course, instead of my_custom_post_type (on line 2 of the snippet) you should use the slug of the post type for which you want to enable content restriction. Once the snippet is in place, the restriction options will be available when editing content of that post type.

Disabling restriction for a specific custom post type

By the same account, you can also remove content restriction for a certain post type — useful when a post type shows restriction options you never intend to use and you want to keep the editing screens tidy. To do this, use the following snippet, which relies on the rsc_skip_post_types filter:

function remove_specific_post_type($post_types){
$post_types[] = 'my_custom_post_type';
return $post_types;
}

add_filter('rsc_skip_post_types', 'remove_specific_post_type', 10, 1);

Again, instead of my_custom_post_type (on line 2 of the snippet) you should use the slug of the post type for which you want to disable content restriction.

How this affects the Post Types settings

In both cases, adding a new post type or removing one will also affect the Post Types area of the Restrict plugin: enabled post types will appear in the Post Types area, which then allows you to select the default content restriction behavior for that post type, while disabled post types will be removed from the Post Types area entirely.

This means the snippets above are the gateway to bulk restriction as well — once a custom post type is enabled, you can set a default restriction for it and apply it to all existing entries from the Post Types screen.

Tips and troubleshooting

  • Use the exact slug. Post type slugs are case-sensitive and often differ from the label shown in the admin menu (the menu might say “Portfolio” while the slug is jetpack-portfolio). If nothing changes after adding the snippet, an incorrect slug is the most common cause.
  • One function name per snippet. If you add snippets for several post types, give each function a unique name (or add multiple slugs to the $post_types array inside a single function) to avoid PHP errors.
  • Some post types may still not be restrictable. Note: the content of some custom post types that a theme or plugin installed on your website is using might not be affected by the Restrict plugin even if you enable content restriction here. This is because some plugins output their content in ways that bypass standard WordPress content filters.
  • Don’t want to touch code? If you don’t feel comfortable doing this yourself or simply don’t want to be bothered with it, you can always contact the support team and they will do it for you.

Related documentation