WordPress at Your Fingertips

has_blocks() WP 1.0

Determine whether a post or content string has blocks.

{{desc}}

Used By: has_block()
1 time — 0.000001 sec (speed of light) | 50000 times — 0.04 sec (speed of light) | PHP 7.2.5, WP 5.0

No Hooks.

Return

true|false. Whether the post has blocks.

Usage

has_blocks( $post );
$post(int|string|WP_Post|null)
Post content, post ID, or post object.
Default: global $post

Notes

Code of has_blocks() WP 5.8.3

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:' );
}

Gutenberg (blocks editor)

No comments
    Log In