Disable Gutenberg on specific posts or pages

april 24, 2018

As most WordPress developers already know, Gutenberg is coming to WordPress very soon. I must admit that I’ve seen Gutenberg getting better over time and reckon it has a lot of potential. Especially for new to be launched websites.

To set the tone I re-launched biancavandepoel.com just last week with a new Gutenberg ready theme and the associated plugin, both called Atomicblocks. Be sure to check these out.

Backward compatibility

My main fear for Gutenberg is how it will behave on existing websites which all have their own specific configuration, plugins and custom code. Things might break. To be honest I think things will break. Last couple of weeks I’ve been preparing websites for the upcoming release in order to prevent them from breaking.  There are several ways to disable the Gutenberg editor.

Disable Gutenberg

There are several posts on the internet that share code pieces how to disable Gutenberg. One of the most comprehensive guides  can be found here. So if you are looking for other ways to disable Gutenberg check out this post by Jeff Starr.

Only on specific posts or pages

However I could not find a (non plugin) way on how to disable Gutenberg only for specific posts or pages. Luckily I found this code piece that showed how to disable the visual editor for specific posts or pages. I tweaked the code a little and you find the result below.

On line three you need to replace 123 with the post ID of the post you want to hide. You can find this id in the source code of the post or by hovering over the edit button of the post in the admin.

My reason for this aproach

Though it’s not exactly clear when Gutenberg is coming, it may be very soon. One of the issues I experienced is the poor compatibility with Advanced Custom Fields.  I’m sure this may be resolved one day soon, but until then this can come in handy.

Disclaimer

Make sure to run the code in a staging area first. Also note that Gutenberg is not officialy released yet so the code snippet above may stop working once you update the plugin. I will try to keep it updated though…