Disabling Gutenberg for specific post types in WordPress is a common need when a custom post type is mostly custom fields. A block canvas adds nothing there, and meta boxes fit better on the classic screen. The Classic Editor plugin switches the whole site, which is more than you want.
This snippet keeps the block editor for posts and pages and opens the classic editor only for the post types you list.
The snippet
<?php
add_filter( 'use_block_editor_for_post_type', 'dpc_disable_block_editor_for_post_types', 10, 2 );
/**
* Use the classic editor for the listed post types.
*/
function dpc_disable_block_editor_for_post_types( $use_block_editor, $post_type ) {
$classic_post_types = array( 'book', 'movie' );
if ( in_array( $post_type, $classic_post_types, true ) ) {
return false;
}
return $use_block_editor;
}
Add it with Scripts Organizer
Scripts Organizer ships this snippet in its One-Click Import library. To add it by hand:
- In wp-admin go to Scripts Organizer → Code Blocks → Add New and give the block a title.
- Script location: PHP.
- Trigger location: Admin only. The editor screen is part of wp-admin, so the code does not need to load on the front end.
- Action hook: leave it empty. The code only registers filters and actions, so it can run while plugins load.
- Paste the snippet into the PHP editor, enable the block and publish it.
The same code also works unchanged in a small plugin or an mu-plugin file in wp-content/mu-plugins/.
How it works
WordPress calls the use_block_editor_for_post_type filter when it decides which editor to load on post.php and post-new.php, and when it builds edit links in the admin. Returning false for a post type sends every post of that type to the classic editor.
For every other type the snippet returns the value it received instead of true. A decision made earlier by WordPress or another plugin, such as a post type without REST support, is kept.
The strict in_array() comparison avoids type juggling, and the function only compares slugs, so it costs nothing on admin requests.
Customise it
Replace book and movie with your own slugs. The slug is the first argument of register_post_type(), and it is also the post_type value in the URL of the list screen, for example edit.php?post_type=book.
To switch single posts rather than a whole type, use the use_block_editor_for_post filter. This example keeps the classic editor for pages that use a landing page template:
add_filter( 'use_block_editor_for_post', 'dpc_classic_editor_for_landing_pages', 10, 2 );
function dpc_classic_editor_for_landing_pages( $use_block_editor, $post ) {
if ( 'templates/landing.php' === get_page_template_slug( $post ) ) {
return false;
}
return $use_block_editor;
}
Gotchas
- A post type registered with
show_in_restset tofalsealready uses the classic editor, because the block editor needs the REST API. - Content written in the block editor keeps its block comments. The classic editor shows them as HTML comments in the Text tab; leave them in place if you may switch back later.
- This only changes the post editor. The Site Editor, the widgets screen and template editing are separate screens.
- If you only want a lighter block editor rather than none, see Disable default block theme patterns.
In the Scripts Organizer library Import it with one click from Scripts Organizer.