Aleš Sýkora / April 12, 2021 / 0 comments
Enable Gutenberg for Custom post type
1 min read / WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: 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: Here is complete example of CPT supporting Gutenberg editor.
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 );
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻