WordPress at a glance
function is not described

has_blocks() WP 5.0.0

Determine whether a post or content string has blocks.

This test optimizes for performance rather than strict accuracy, detecting the pattern of a block but not validating its structure. For strict accuracy, you should use the block parser on post content.

  • See: parse_blocks()

No Hooks.


true/false. Whether the post has blocks.


has_blocks( $post );
Post content, post ID, or post object.
Default: global $post

Code of has blocks: wp-includes/blocks.php VER 5.1.1

function has_blocks( $post = null ) {
	if ( ! is_string( $post ) ) {
		$wp_post = get_post( $post );
		if ( $wp_post instanceof WP_Post ) {
			$post = $wp_post->post_content;

	return false !== strpos( (string) $post, '<!-- wp:' );