How to Disable Gutenberg Selectively without Plugin

There are a lot of plugins to disable Gutenberg editor. But the code to disable it is actually very short and simple. So no need for plugin, just add this snippet in your theme's functions:

Gutenberg (also knows as Block Editor) is the official drag-n-drop builder in WordPress version 5.0+.

There are a lot of plugins to disable Gutenberg editor. But the code to disable it is actually very short and simple. So no need for plugin, just add this snippet in your theme’s functions:

add_filter( 'use_block_editor_for_post', '__return_false' );

Yes, I’m serious. it’s only that 1 line.

There are cases when you want to enable Gutenberg only in some condition. Below are some common examples:

Allow Gutenberg for Posts Only

We use the same filter and return true if it’s on post edit page.

add_filter( 'use_block_editor_for_post', 'my_disable_gutenberg', 10, 2 );

function my_disable_gutenberg( $can_edit, $post ) {
  if( $post->post_type == 'post' ) {
    return true;
  }

  return false;
}

Allow for Page with the Template “Allow Gutenberg”

First, create a new Page Template, take note of the file name:

<?php
/**
 * Template Name: Allow Gutenberg
 */

require_once 'page.php';

Then, still using the same filter, add a conditional to check if it’s using that page template:

add_filter( 'use_block_editor_for_post', 'my_disable_gutenberg', 10, 2 );

function my_disable_gutenberg( $can_edit, $post ) {
  if( $post->post_type == 'page' &&
    get_page_template_slug( $post->ID ) == 'page-gutenberg.php' ) {
    return true;
  }

  return false;
}

Conclusion

There are many reasons to disable Gutenberg. Maybe you already use another Page Builder? Maybe it lacks the control ACF provides?

For old site, you generally want to fully disable it. But you might want to have a little taste of Gutenberg by enabling it on Blog Post only. You can do so by following the code above.

Let us know why you disable Gutenberg in the comment below 🙂

Default image
Henner Setyono
A web developer who mainly build custom theme for WordPress since 2013. Young enough to never had to deal with using Table as layout.
Leave a Reply