How to dynamically enable Gutenberg

Whatever your stance is on Gutenberg – it’s coming to WordPress core really soon. There is an easy way to enable/disable the new WordPress editor dynamically using good ol’ filters.

Since Gutenberg version 3.5 there is a filter available called gutenberg_can_edit_post and in WordPress core the same filter is available under the name: use_block_editor_for_post.

Disable by default

In WordPress 5.0 Gutenberg is going to be enabled by default, but I’m going to assume that your default for Gutenberg is to have it turned off. You can turn off Gutenberg by default by either using a plugin like Gutenberg Ramp or with a simple __return_false WordPress filter.

The snippets below are going to assume that $can_edit is false by default, if you want to disable Gutenberg by default, you can do this:

Now that Gutenberg is disabled by default, here are a few snippets you could use…

Enable Gutenberg only for new posts

Enabling Gutenberg for new posts consists of 2 parts – first – check if the current screen is the post-new.php page ( for creating a new post ), and then the second bit uses a function called has_blocks() that’s built into Gutenberg and WordPress 5.0 to check if the post content has Gutenberg blocks already in it – this is to make sure that posts written in Gutenberg – stay in Gutenberg.

Enable Gutenberg based on Post Meta

You can also load Gutenberg based on post meta data. In this case I’m enabling Gutenberg if the post meta foobar_setting has the value Quick brown fox, but you can get as creative as you need to be with this:

Enable Gutenberg for a certain category or tag

Putting it all together – you can enable Gutenberg for all new posts and for all posts in a certain category, and have Gutenberg disabled everywhere else. This is just to illustrate that the filter is very flexible: