Hello Gutenberg! Yes, This is first of my post with Gutenberg! that’s a very good editor for authors and I love them because I got good feeling at first.
Enable in post types
For other post types, if you want to enable the Gutenberg, just make sure show_in_rest
function book_post_type() { $args = array( 'label' => 'Book', 'public' => true, 'rewrite' => array( 'slug' => 'book' ), 'capability_type' => 'post', 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ), 'show_in_rest' => true, ); register_post_type( 'book', $args ); } add_action( 'init', 'book_post_type' );
Disable in post types
It’s okay if that argument is false, but for making sure that is disabled, you can use the below hook.
function post_type_filter( $use_block_editor, $post_type ) {
if ( 'books' === $post_type ) {
return false;
}
return $use_block_editor;
}
add_filter( 'use_block_editor_for_post_type', 'post_type_filter', 10, 2 );
I am having an error enabling Gutenberg. Can you please help me as I am having issues in this line of code
register_post_type( ‘portfolio’,
// WordPress CPT Options Start
array(
‘labels’ => array(
‘name’ => __( ‘Portfolio’ ),
‘singular_name’ => __( ‘Portfolio’ )
),
‘has_archive’ => true,
‘public’ => true,
‘rewrite’ => array(‘slug’ => ‘portfolio’),
)
);
}
Reference: https://www.cloudways.com/blog/gutenberg-wordpress-custom-post-type/
Please add
show_in_rest
arg in your code.