has_block

SummerySummery

Determine whether a $post or a string contains a specific block type.

Syntax

has_block( string $block_name, int|string|WP_Post|null $post = null )

DescriptionDescription

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

ParametersParameters

$block_name

(string) (Required) Full Block type to look for.

$post

(int|string|WP_Post|null) (Optional) Post content, post ID, or post object. Defaults to global $post.

Default value: null

ReturnReturn

(bool) Whether the post content contains the specified block.

SourceSource

File: wp-includes/blocks.php


			

ChangelogChangelog

Changelog
Version Description
5.0.0 Introduced.

See alsoSee also

Scroll to Top