Helping you build a better website
(and other interesting web stuff)

CSSHTMLJavaScriptjQueryMSSQLMySQLPHPSilvaTechnologiesWordpress
Silva Web Designs - Blog

How to Disable Gutenberg without a Plugin

Most people use the plugin ‘Classic Editor’ to disable Gutenberg, but did you know that it is actually really simple to do this with code? With over 5 millions installs, it’s quite clear that a lot of people go for the simple option.

The code needed to disable it is actually very short and simple, so there is no need for a plugin to do the job, just add the following snippet in your theme’s functions.php file:


    add_filter( 'use_block_editor_for_post', '__return_false' );

Yup, it’s that simple… just one line of code!

There are cases where you may want to enable Gutenberg only in some condition. Below are some frequently used 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 on your WordPress site. Maybe you already use another Page Builder or it simply lacks the control ACF provides?

For old sites, 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. 🙂

Hope that helps!

Leave a comment if this has helped you or why you choose to disable Gutenberg.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development and web site design. His expertise is WordPress & Magento as well as many other frameworks. Would you like to work with Nathan? Send him an email on [email protected]

It’s good to share

Join the discussion