Since WordPress 5.0, the block editor, also known as Gutenberg, has been the default editor for posts and pages. It’s great for building layouts, but some writers still prefer the old classic editor for plain articles. You don’t always need a plugin for that. With the following code, your posts open in the classic editor, while pages keep the block editor. Want to go the other way? Read our guide to activate the Gutenberg editor in WordPress.
Where to place? functions.php of your child theme, or a code snippets plugin.
Usage
- For writers who are used to the classic editor and want a simple text box for articles.
- On older websites where most posts were written in the classic editor and should stay that way.
- To keep the block editor for page layouts while using a simpler editor for daily posts.
Code
// Use the classic editor for posts, keep the block editor for pages
function wpt_disable_block_editor_for_posts( $use_block_editor, $post_type ) {
if ( 'post' === $post_type ) {
return false;
}
return $use_block_editor;
}
add_filter( 'use_block_editor_for_post_type', 'wpt_disable_block_editor_for_posts', 10, 2 );
To switch another post type instead, change 'post' to its name, for example 'product'. Posts that were built with blocks will open in the classic editor as HTML, so check them before you edit.
Explanation
- Just a comment to identify the code.
- Declaring the
wpt_disable_block_editor_for_postsfunction. It receives$use_block_editor(whether WordPress wants to use the block editor) and$post_type(the type of content being edited). - Checking whether the content being edited is a post.
- If it is, returning
falseso WordPress opens the classic editor. - Closing the if statement.
- For everything else, returning WordPress’s own choice unchanged.
- Closing the function.
- Adding our function to the
use_block_editor_for_post_typefilter. The2at the end tells WordPress our function takes two arguments.