Enable Gutenberg for Custom post type

Author: Aleš Sýkora, 12. 4. 2021

If you create Custom post type in WordPress and want to use Gutenberg editor instead of classic editor, you need to add this in your code:

    'show_in_rest' => true,
       'supports' => array('editor')

Here is complete example of CPT supporting Gutenberg editor.

// Register Custom Post Type Career
function as_cpt_career() {

	$labels = array(
		'name'                  => _x( 'career', 'Post Type General Name', 'text_domain' ),
		'singular_name'         => _x( 'career', 'Post Type Singular Name', 'text_domain' ),
		'menu_name'             => __( 'career', 'text_domain' ),
		'name_admin_bar'        => __( 'career', 'text_domain' ),
	);
	$args = array(
		'label'                 => __( 'career', 'text_domain' ),
		'description'           => __( 'career', 'text_domain' ),
		'labels'                => $labels,
		'show_in_rest'			=> true,
		'supports'              => array( 'title', 'editor', 'revisions', 'custom-fields' ),
		'hierarchical'          => false,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => 5,
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'has_archive'           => false,
		'exclude_from_search'   => true,
		'publicly_queryable'    => false,
		'capability_type'       => 'page',
	);
	register_post_type( 'career', $args );

}
add_action( 'init', 'as_cpt_career', 0 );