Check if current page is using blocks (Gutenberg) or is legacy

Is there a way to know if a page is using Gutenberg or not?

The use case is migrating an old post to Gutenberg and letting crafted pages just render themselves with blocks but add some wrapping around old pages which probably won't be migrated since they're just text (Privacy policy and those). They need to coexist at least for a while.

A block editor page can usually be just rendered with

?php

get_header();

while (have_posts()) :
  the_post();
  the_content();
endwhile;

get_footer();

While I have that handled for the homepage using a p front-page.php template, I'd like to have a generic template that can handle both types so I don't have to go slug by slug.

Topic block-editor Wordpress

Category Web


I know it's been awhile, but yes. You can check if a post uses blocks, check out has_blocks() : https://developer.wordpress.org/reference/functions/has_blocks/

I'm using it when filtering content, to see if I need to parse blocks or not.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.