How to disable Gutenberg / block editor for certain post types?
WordPress introduced the Gutenberg block editor in version 5, and it has become the default interface for managing post and page content types. While this shift offers a robust editing experience for standard blog posts and pages, it presents a specific challenge for developers maintaining custom workflows. If you have registered custom post types (CPTs) via your theme or plugin, you might find that these new editors are either already active or potentially enabled in future WordPress updates.
The core issue is that Gutenberg is not just a standalone feature; it is the default editor mechanism for all post types unless explicitly overridden. As a developer, you need to ensure that specific CPTs continue to use the Classic Editor while standard posts utilize the modern block system. This distinction allows you to leverage new features for general content while maintaining stable, familiar interfaces for complex data structures defined by your custom types.
To disable the editor for a specific post type, you must hook into the use_block_editor_for_post_type filter. This filter determines whether the block editor should be rendered for a given post type. By returning false, you effectively revert to the classic TinyMCE-based editor.
Here is how you implement this logic within your theme's functions.php file or your plugin main file:
add_filter('use_block_editor_for_post_type', function( $use_block_editor, $post_type ) {
// Define the specific custom post type(s) to exclude
$excluded_post_types = [ 'your_custom_cpt_name' ];
if ( in_array( $post_type, $excluded_post_types ) ) {
return false;
}
return $use_block_editor;
}, 10, 2 );
In this example, replace 'your_custom_cpt_name' with the actual slug of your custom post type. The function accepts two arguments: $use_block_editor, which is a boolean indicating whether the block editor should be used by default, and $post_type, which contains the current post type being edited. By checking if $post_type matches one of your exclusions, you return false to bypass the block editor.
It is important to understand the implications of this change. Disabling Gutenberg for a specific CPT means users will see the classic toolbar and content area. However, the underlying data storage remains compatible; the system still saves content as serialized HTML or JSON depending on the theme's configuration, though the input experience changes significantly. If your custom post type relies on block attributes (like align or spacer) for layout, disabling the editor will prevent users from adding these blocks via the UI, potentially breaking existing layouts if those were added manually.
Furthermore, consider the dependency on external libraries. The Classic Editor plugin (classic-editor) is often suggested as a solution to force the classic editor globally. However, relying on a third-party plugin to handle logic that WordPress core supports via filters is generally unnecessary and can introduce conflicts. Using the native filter keeps your solution lightweight and dependent only on WordPress core functionality.
If you are building a site where specific CPTs require complex form fields or legacy data structures that do not integrate well with the block editor, this approach ensures stability without waiting for future updates to potentially force the new interface on your custom types. Always verify the behavior in a staging environment before applying these changes to production sites, as user expectations regarding the editing interface can vary significantly between teams.