Skip to content

Block editor

The WordPress block editor is the content editing and site building experience built into WordPress Core. The block editor is the WordPress editor enabled by default, replacing the classic editor.

Note

Upcoming beta features for the block editor can be tested by installing and activating the Gutenberg plugin on a non-production environment.

The Gutenberg plugin is only intended for testing and development purposes, and should not be added to a production environment due to the experimental nature of the releases.

The block editor is dependent on the WordPress REST API. For this reason, only post types registered with 'show_in_rest' => true are compatible with the block editor. For post types that are incompatible with the block editor—or have the block editor disabled—the classic editor will load instead.

The block editor can be selectively enabled or disabled for post types or specific posts. When adding custom code to enable or disable the block editor, the use_block_editor_for_post_type filter or the use_block_editor_for_post filter can be used to adjust if a post can be edited with the block editor.

Note

Custom code that modifies the loading behavior of the block editor should be added to a custom plugin file. If a filter is set in multiple places in application code, modifications to the filter priority might be necessary.

Enable or disable for all post types

The use_block_editor_for_post filter can be assigned a callback of __return_true or __return_false to control the loading behavior of the block editor for all post types.

This example demonstrates disabling the block editor for all post types:

/client-mu-plugins/example-plugin.php
add_filter( 'use_block_editor_for_post', '__return_false'  );

Enable or disable for specific post types

The block editor can be selectively enabled or disabled per post type by passing a post_type string to the use_block_editor_for_post_type filter and the custom function calling the filter.

This example demonstrates enabling the block editor only for the page post type:

/client-mu-plugins/example-plugin.php
add_filter( 'use_block_editor_for_post_type', 'disable_block_editor_for_page_post_type', 10, 2 );

function disable_block_editor_for_page_post_type( $use_block_editor, $post_type ) {
        return ( 'page' === $post_type ) ? false : $use_block_editor;
}

Enable or disable for specific post IDs

The use_block_editor_for_post filter accepts post IDs and WP_Post objects (e.g. a post type). This makes it possible to selectively enable or disable the block editor for posts based on author, ID, and more.

In this example, the block editor is selectively enabled only for post IDs 114, 285, and 352, and disabled for all other posts:

/client-mu-plugins/example-plugin.php
add_filter( 'use_block_editor_for_post', 'maybe_load_block_editor_for_post_id', 20, 2 );

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

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

To selectively disable the block editor for specific post IDs, modify the above code example to invert (!) the value returned from the in_array() call.

Last updated: May 03, 2024

Relevant to

  • WordPress