Skip to content

Plugins

Gutenberg

The Block Editor (Gutenberg) is the default WordPress editor, but the Classic Editor can be selectively enabled via filters.

Disabling for all post types

Loading behavior is controlled by setting use_block_editor_for_post to __return_true or __return_false. This setting should be added to a theme’s functions.php and will affect all post types.

In this example, the block editor is disabled for all post types:

add_filter( 'use_block_editor_for_post', '__return_false'  );

If this filter is set in multiple places in an application’s code, the priority of the filter might need to be changed.

Disabling for specific post types

Enabling the block editor for specific post types requires that the post type is registered with 'show_in_rest' => true. The block editor depends on the REST API, and if the post type is not shown in the REST API it will not work with the block editor.

In this example, the block editor is set to load only for page post types:

function maybe_load_gutenberg_for_post_type( $can_edit, $post ) {
        $enable_for_post_types = [ 'page' ];
        if ( in_array( $post->post_type, $enable_for_post_types, true ) ) {
                return true;
        }
        return false;
}
add_filter( 'use_block_editor_for_post', 'maybe_load_gutenberg_for_post_type', 15, 2 );

Enabling or disabling for specific post IDs

The block editor can be selectively enabled for specific post IDs while remaining disabled for all other posts.

In this example, the block editor is only enabled for post IDs 114, 285, and 352:

function maybe_load_gutenberg_for_post_id( $can_edit, $post ) {
     $enable_for_post_ids = array( 114, 285, 352 );

     if ( in_array( $post->ID, $enable_for_post_ids, true ) ) {
          return true;
     }

     return false;
}

add_filter( 'use_block_editor_for_post', 'maybe_load_gutenberg_for_post_id', 20, 2 );

To selectively disable the block editor for specific post IDs, modify the above example to return false instead of true for post IDs not in the $enable_for_post_ids array.

Last updated: September 14, 2022