By default, a WordPress custom post type does not use the Gutenberg editor. Why? In this quick tip, I’ll walk you through the why and show you how to enable the Gutenberg editor for your custom post types. Don’t worry. It’s literally one configuration parameter.
Gutenberg uses the REST API. But by default, the REST API parameter turned off when you register a custom post type. Therefore, you need to intentionally turn it on in your code. Let me show you how.
The Code
Here is a link to the Books plugin gist if you want to work along with me.
In the configuration arguments where you register the custom post type, add the following configuration parameter:
'show_in_rest' => true, // To use Gutenberg editor.
For example, let’s say you are registering a Book post type. The registration arguments might be:
function sitegrows_register_book_post_type() {
$labels = [
// left out for brevity.
];
$args = [
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true, // To use Gutenberg editor.
'query_var' => true,
'rewrite' => [ 'slug' => 'book' ],
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
];
register_post_type( 'book', $args );
}