5

I understand that you have to enable the REST API in order to use the Gutenberg block editor, because Gutenberg relies on it; however, I want to use the Classic Editor for a custom post type and still use the REST API. Is there another way to disable Gutenberg?

I am aware that setting show_in_rest to true in my register_post_type() function enables the REST API, but it also enables Gutenberg when I do.

Any suggestions are greatly appreciated.

1
  • it would be more accurate to say that gutenberg is already enabled, but when show_in_rest is set to false it is disabled. You should be able to disable the block editor when registering your post type without needing to mention show_in_rest. I did notice your registration code is missing from your question though, I assume you've added editor in the supports section if you're seeing this behaviour?
    – Tom J Nowell
    Jan 4 at 16:30

1 Answer 1

4

This code should do the trick. You will just need to add the post type(s) to the line below.

function my_disable_gutenberg( $current_status, $post_type ) {

    // Disabled post types
    $disabled_post_types = array( 'book', 'movie' );

    // Change $can_edit to false for any post types in the disabled post types array
    if ( in_array( $post_type, $disabled_post_types, true ) ) {
        $current_status = false;
    }

    return $current_status;
}
add_filter( 'use_block_editor_for_post_type', 'my_disable_gutenberg', 10, 2 );
1
  • Works perfectly. Thanks!
    – Aristocles
    Jan 4 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.