How to Enable Gutenberg Block Editor For Custom Post Type

If you are using the Gutenberg block editor for your WordPress site, and you created a new custom post type, you will notice that it will not show the block editor by default. All you will see is the old classic editor. If you are looking for a consistent editing experience across the board, you might want to switch out the classic editor to the block editor. Here is the easiest way to enable Gutenberg editor for custom post type.

Enable Gutenberg for custom post type

To get started, we will need to have a custom post type. For this example, we will register a simple custom post type using the code below (in the functions.php file):

add_action( 'init', 'register_movie_custom_post_type' );
function register_movie_custom_post_type() {
    $args = array(
        'public' => true,
        'has_archive' => true,
        'show_ui' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'show_in_menu' => true,
        'query_var' => true,
        'supports' => array( 'title', 'editor', 'comments', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'revisions' ),
    );
 
    register_post_type(  'movie', $args );
}

Notice that the code above has a “supports” field and an “editor” value. This is necessary for the custom post type to display the post editor in the “Add New” page.

To enable Gutenberg for this custom post type, all we need is to add ‘show_in_rest' => true, in the $arg array. Here is how it looks like:

add_action( 'init', 'register_movie_custom_post_type' );
function register_movie_custom_post_type() {
    $args = array(
        'public' => true,
        'has_archive' => true,
        'show_ui' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'show_in_menu' => true,
        'query_var' => true,
        'show_in_rest' => true,
        'supports' => array( 'title', 'editor', 'comments', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'revisions' ),
    );
 
    register_post_type( 'movie', $args );
}

That’s it.