Getting your plugins ready for Gutenberg

Is your site, its plugins, custom post types, custom meta and your content ready for Gutenberg?

Remember the release date: 5th 6th 7th December 2018.

TL;DR

Until you’ve tested everything, a short-term fix could be to turn off the Gutenberg experience:

add_filter('use_block_editor_for_post', '__return_false');

If you own, manage, develop or have any vested interest in a WordPress powered website, or blog, then the imminent WordPress Version 5, with the all-new Gutenberg editor, will either be welcomed or feared (we’re in both camps).

Before we go any further, let’s quickly get an overview of what this Gutenberg thing is.

What is Gutenberg?

At the heart of WordPress is the editor, where the majority of content is created (hence why it’s displayed to the webpage by calling the_content()). Up until Gutenberg composing content was done in a TinyMCE editor. But not with the Gutenberg revolution.

Gutenberg dramatically shifts the editing experience, moving the focus away from a single, confined editing pane and replacing it with a block-based, drag and drop content composer.

So Gutenberg can be seen more as a page builder than its more confined predecessor.

This leads us to the elephant in the room:

Will Gutenberg break my site?

The short answer

Possibly not, but definitely check, especially the editing experience!

The longer answer

Test everything in a development and/or staging environment.

  • Do all plugins behave as expected?
  • Does the Gutenberg editor show all your custom metaboxes?
  • Does all the custom content appear on the frontend?
  • Can existing content be edited in Gutenberg?

I could walk through each of these with you and suggest fixes for each, but the article would take a whole lot more time to write (that said, the next section touches on this). Delicious Brains has a great article on preparing your plugins for Gutenberg, that walks through testing and updating plugins and post types to be compatible, I’d strongly suggest reading it, as it covers a lot of the issues you may encounter.

Do I have to use Gutenberg – can’t I just use the old editor?

YES, you can continue using the old editor!

There’s quite a bit of flexibility, too, as you can opt to ignore Gutenberg globally (for now), or conditionally opt out.

Gobally ignore Gutenberg

To stay with the old editor and ignore the new Gutenberg editor entirely (for now at least), add the following code to your theme’s functions.php file:

add_filter('use_block_editor_for_post', '__return_false');

Conditionally ignore Gutenberg for pages

If you’re feeling confident that Gutenberg is fine on blog posts, but would prefer to stick with the old editor on pages, then add the following filter to your theme’s functions.php files:

add_filter('use_block_editor_for_post_type', function ($is_enabled, $post_type) {
    // pages will not Gutenberg
    if ($post_type === 'page') return false;
    
    return $is_enabled;
}, 10, 2);

Conditionally ignore Gutenberg when using custom meta boxes

If you only want to disable it on pages and posts that have specific custom meta boxes, then you can to add __block_editor_compatible_meta_box' => false to the meta box’s callback_args array. For example:

add_meta_box(
    'your_metabox_id',     // $id       string
    'Your Metabox Title',  // $title    string
    'metabox_callback',    // $callback callable
     null,                 // $screen   string|array|WP_Screen
    'normal',              // $context  string
    'default',             // $priority string
    array('__block_editor_compatible_meta_box' => false) // $callback_args array
);

For more info on meta boxes, please refer to the official WordPress Developer pages.

Conclusion

WordPress 5 + Gutenberg is imminent here! This is definitely a great step forwards for WP and if you update your sites to work with it, you will enjoy all the goodness of working with blocks. If you have a WordPress site and you would like help with updating to version 5, please get in touch and we will help you through the process.