Last updated on October 24, 2023

Disable Gutenberg Editor (enable Classic Editor)

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Disable the Gutenberg editor programmatically and enable the Classic editor.

What is Gutenberg in WordPress?

Gutenberg is a block-based content editor for WordPress, introduced in WordPress 5.0. It’s named after Johannes Gutenberg, the inventor of the printing press, because it represents a significant shift in how content is created and edited within the WordPress platform.

Before Gutenberg, WordPress primarily used the so called Classic Editor where users worked with a single content field. With the introduction of Gutenberg, content creation in WordPress became more flexible and user-friendly. Instead of a single text field, Gutenberg divides content into “blocks.” These blocks can represent different types of content elements, like paragraphs, headings, images, videos, quotes, and more. Users can easily create and arrange these blocks to build complex layouts within the WordPress editor.

Some key features and benefits of Gutenberg include:

  1. Block-Based Editing: Each piece of content is treated as an individual block, making it easier to manipulate and organize content.
  2. Rich Content Blocks: Gutenberg includes a wide variety of content blocks for text, multimedia, widgets, and more. These blocks can be easily added and customized.
  3. WYSIWYG Experience: Gutenberg provides a “What You See Is What You Get” experience, making it simpler for users to see how their content will appear on the front end of their website as they edit it.
  4. Reusable Blocks: You can save and reuse custom blocks, which is especially useful for maintaining consistency in your website’s design.
  5. Full-Site Editing: In more recent updates, Gutenberg has expanded its capabilities to support full-site editing, allowing users to create and edit entire web page layouts using blocks.
  6. Extensible: Developers can create custom blocks and extend Gutenberg’s functionality with plugins and custom code.
  7. Responsive Design: Gutenberg encourages the creation of responsive designs, making it easier to create websites that look good on various devices.

Gutenberg has received mixed reactions from the WordPress community, with some users embracing the new editor’s flexibility and ease of use, while others have expressed concerns about the learning curve and compatibility with existing content. Nonetheless, Gutenberg represents a significant step in WordPress’s evolution and is an essential part of the platform for content creators and developers alike. However, you might run into a situation where you want to disable Gutenberg in favor of the Classic Editor.

Disable the Gutenberg Block Editor Site-wide

You can disable Gutenberg for all content in WordPress, you can disable the Gutenberg Editor using the following code snippet:

add_filter('gutenberg_can_edit_post', '__return_false', 5);
add_filter('use_block_editor_for_post', '__return_false', 5);

This code uses the gutenberg_can_edit_post and use_block_editor_for_post filter hooks to disable the Gutenberg Editor and enable the Classic Editor for all posts. Once you have added this code snippet, the Classic Editor will be enabled and the Gutenberg Block Editor will be disabled.

Disable Gutenberg per post type

In order to conditionally enable/disable the Gutenberg Block Editor for specific post types, you can use the use_block_editor_for_post filter hook. It accepts two parameters: The first parameter is a boolean (true if Gutenberg is enabled, false otherwise) and the second parameter is the post type slug. You can use this filter hook for both built-in and custom post types.

Disable Gutenberg Block Editor for a single specific post type

The following code snippet can be used to do disable the Gutenberg Block Editor for a single specific post type, including custom post types:

/**
 * Filter whether or not the Gutenberg Block Editor should be enabled for specific post types
 *
 * @param bool    $use_block_editor   Whether the post type can be edited or not. Default true.
 * @param string  $post_type          The slug of the post type being checked.
 * @return bool   Returns true if the Gutenberg Block editor should be enabled.
 */
function wpsnippets_disable_gutenberg_conditionally ( $use_block_editor, $post_type ) {

    // Change 'post' to the post type you want to disable Gutenberg for
    if ( $post_type === 'post' ) {
        return false;
    }

    return $use_block_editor;
}

add_filter( 'use_block_editor_for_post_type', 'wpsnippets_disable_gutenberg_conditionally', 10, 2 );

This code adds a filter that disables the Gutenberg Editor for the post post type. You can modify the post type slug post to match another post type, or a custom post type.

Disable/enable the Gutenberg Block Editor for multiple specific post types

If you have multiple (custom) post types that you want to disable the Gutenberg Editor for, you can check for multiple post types at the same time:

/**
 * Filter whether or not the Gutenberg Block Editor should be enabled for specific post types
 *
 * @param bool    $use_block_editor   Whether the post type can be edited or not. Default true.
 * @param string  $post_type          The slug of the post type being checked.
 * @return bool   Returns true if the Gutenberg Block editor should be enabled.
 */
function wpsnippets_disable_gutenberg_conditionally ( $use_block_editor, $post_type ) {

    // Define the post types you want to disable Gutenberg for
    $classic_editor_post_types = array(
        'post',
        'location',
        'book',
    );

    // Disable Gutenberg for all post types in $classic_editor_post_types
    if ( in_array( $post_type, $classic_editor_post_types ) {
        return false;
    }

    return $use_block_editor;
}

add_filter( 'use_block_editor_for_post_type', 'wpsnippets_disable_gutenberg_conditionally', 10, 2 );

This code snippet checks for the post, location and book post types, and disables Gutenberg for these post types. You can modify these slugs to match other post types, including custom post types.

Last updated on October 24, 2023. Originally posted on April 30, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *