How to Allow Gutenberg Editor for Custom Post Types

Gutenberg has been the default editor in WordPress since version 5.0. However, it does not automatically appear for Custom Post Types (CPTs).

By default, custom post types use the classic editor. To enable the block editor for a CPT, two conditions must be met during registration.

To enable Gutenberg for a custom post type, you must set show_in_rest to true and include editor in the supports array. Missing either one will keep the classic editor active.

Basic Example

Here is a typical custom post type registration without Gutenberg support:

function savvy_cpt_init() {

    $labels = array(
        // not relevant for this article
    );

    $args = array(
        'labels'             => $labels,
        'description'        => __( 'Description.', 'textdomain' ),
        'public'             => true,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    );

    register_post_type( 'newcpt', $args );

}
add_action( 'init', 'savvy_cpt_init' );

To enable Gutenberg for this content type, add show_in_rest set to true:

function savvy_cpt_init() {

    $labels = array(
        // not relevant for this article
    );

    $args = array(
        'labels'             => $labels,
        'description'        => __( 'Description.', 'textdomain' ),
        'public'             => true,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
        'show_in_rest'       => true,
    );

    register_post_type( 'newcpt', $args );

}
add_action( 'init', 'savvy_cpt_init' );

Why Is show_in_rest Required?

Gutenberg is built on top of the WordPress REST API. The editor uses REST endpoints to load, save, and validate post content. Setting show_in_rest to true exposes your custom post type to these endpoints, which is a prerequisite for the block editor to function.

If you need to customize the REST API route for your CPT, you can use the rest_base parameter to change the endpoint slug and rest_controller_class to specify a custom controller.

Without show_in_rest, WordPress falls back to the classic TinyMCE editor – even if editor is included in the supports array. This is also the reason why some developers disable Gutenberg by removing REST API support from specific post types.

Is Your Custom Post Type Now Exposed in the REST API?

Yes. Anyone can read its published entries at /wp-json/wp/v2/{rest_base} without logging in. This is true even when public is set to false. Drafts and private entries stay hidden from anonymous visitors.

If published entries must stay private, block the route for users who lack permission. Replace book with your post type’s rest_base:

function savvy_protect_book_rest( $result, $server, $request ) {
    $is_book_route = preg_match( '#^/wp/v2/book(/|$)#', $request->get_route() );

    if ( $is_book_route && ! current_user_can( 'edit_posts' ) ) {
        return new WP_Error(
            'rest_forbidden',
            'You are not allowed to read this content.',
            array( 'status' => rest_authorization_required_code() )
        );
    }

    return $result;
}
add_filter( 'rest_pre_dispatch', 'savvy_protect_book_rest', 10, 3 );

Enabling Gutenberg for a CPT You Did Not Register

When a plugin or theme registers the post type, don’t edit its files. Use the register_post_type_args filter to change the arguments. Add this to a small plugin or your child theme:

function savvy_enable_block_editor( $args, $post_type ) {
    if ( 'book' === $post_type ) {
        $supports = isset( $args['supports'] ) ? (array) $args['supports'] : array( 'title', 'editor' );

        $args['supports']     = array_unique( array_merge( $supports, array( 'editor' ) ) );
        $args['show_in_rest'] = true;
    }

    return $args;
}
add_filter( 'register_post_type_args', 'savvy_enable_block_editor', 10, 2 );

Still seeing the classic editor? Some plugin or theme is probably turning the block editor off through the use_block_editor_for_post_type filter. Run your own callback later to override it:

function savvy_force_block_editor( $use_block_editor, $post_type ) {
    return 'book' === $post_type ? true : $use_block_editor;
}
add_filter( 'use_block_editor_for_post_type', 'savvy_force_block_editor', 100, 2 );

This filter can’t replace the two requirements. WordPress checks editor support and show_in_rest first, and the filter only runs when both pass.

Showing Taxonomies and Custom Fields in the Editor

Custom taxonomies need their own show_in_rest. Without it, their panel won’t appear in the block editor sidebar. Custom fields registered for the REST API also require custom-fields support on the post type:

register_taxonomy( 'genre', 'book', array(
    'label'        => 'Genres',
    'show_in_rest' => true,
) );

// The 'book' post type must include 'custom-fields' in its 'supports' array.
register_post_meta( 'book', 'subtitle', array(
    'type'         => 'string',
    'single'       => true,
    'show_in_rest' => true,
) );

Setting Default Block Templates for a CPT

Once Gutenberg is enabled, you can define a default block template that pre-populates the editor whenever a new post of that type is created. This is done using the template parameter:

$args = array(
    'public'       => true,
    'show_in_rest' => true,
    'supports'     => array( 'title', 'editor', 'thumbnail' ),
    'template'     => array(
        array( 'core/image', array( 'align' => 'wide' ) ),
        array( 'core/heading', array( 'placeholder' => 'Add subtitle...' ) ),
        array( 'core/paragraph', array( 'placeholder' => 'Write content...' ) ),
    ),
);

register_post_type( 'portfolio', $args );

You can also lock the template to prevent editors from adding, removing, or reordering blocks by setting template_lock:

$args = array(
    'public'        => true,
    'show_in_rest'  => true,
    'supports'      => array( 'title', 'editor', 'thumbnail' ),
    'template'      => array(
        array( 'core/image', array( 'align' => 'wide' ) ),
        array( 'core/heading' ),
        array( 'core/paragraph' ),
    ),
    'template_lock' => 'all',
);

register_post_type( 'portfolio', $args );

Setting template_lock to all prevents inserting, moving, or removing blocks. With insert, editors can still move the existing blocks, but they can’t add new ones or remove any. A third value, contentOnly, limits editing to the content inside the blocks.

If you are working with ACF, take a look at the guide on creating custom Gutenberg blocks with ACF and block.json. It is a powerful way to build structured content types with a visual editing experience.

FAQs

Common questions about enabling Gutenberg for custom post types:

Why is my custom post type still showing the classic editor?
The two most common causes are a missing show_in_rest => true parameter in your register_post_type() call, or the absence of editor in the supports array. Both are required for Gutenberg to load. Also check that no plugin or theme is forcing the classic editor for that post type.
Does show_in_rest make my custom post type publicly accessible via the REST API?
Yes. Anyone can read published entries through the REST API without logging in, even if public is false. Drafts and private entries are not readable by anonymous visitors. To protect published entries, restrict the route with the rest_pre_dispatch filter or a custom REST controller.
Can I use Gutenberg for a CPT that is not public?
Yes. You can set public to false and still enable Gutenberg by setting show_in_rest to true and show_ui to true. The REST API exposure is needed for the editor, but it does not require the post type to have a public-facing archive or single template.
What does template_lock do?
The template_lock parameter controls whether editors can modify the block structure defined in the template parameter. Setting it to all prevents adding, removing, or moving blocks. Setting it to insert prevents adding or removing blocks but allows reordering. Omitting it gives editors full control.
Do I need to flush rewrite rules after adding show_in_rest?
No. REST API routes are registered on each request, so adding show_in_rest or changing rest_base does not require a flush. If you also change the rewrite slug or has_archive, visit Settings > Permalinks once. Never call flush_rewrite_rules() on every page load.

Summary

Enabling Gutenberg for a custom post type takes two things: show_in_rest set to true and editor support. The first exposes the post type to the REST API, which the block editor depends on, so check what that makes public.

Beyond basic activation, you can take advantage of block templates to pre-populate the editor with a specific block structure, and lock the template to enforce content consistency. These features make CPTs with Gutenberg a powerful tool for structured content editing.

Summarize with AI Claude ChatGPT Google AI
Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!