There may be times when you need to detect use of Gutenberg on a per-post level – for example, a plugin that adds specific Gutenberg functionality, or maybe to display specific content on Gutenberg pages.
With plugins such as Gutenberg Ramp available, making it easy to specify specific groups of posts that should use Gutenberg, plus the fact that only posts you edit/add after installing Gutenberg will make use of its new functionality, it’s easy to see that most sites will end up with a mixed estate.
The following simple function will add a simple
is_gutenberg() function that you can call to check the status of the current post (I leave it to you to check for whether it’s a single post, etc). It returns either a
2 replies on “Detecting per-post use of Gutenberg”
Thank you so much for this! Just a heads up though – you’re missing the closing parenthesis on the if statement and gutenberg_post_has_blocks() has now been deprecated in favor of has_blocks().
I found that has_blocks() – previously gutenberg_post_has_blocks() – does not reliably detect Gutenberg when you create a new post (in WP 5.0.2). That’s because the post is still empty, while has_blocks() checks for the substring ‘<!– wp:' https://github.com/WordPress/gutenberg/blob/master/lib/register.php