has_block
has_block ( $block_name, $post = null )
Parameters:- (string) block_name Full block type to look for.
- (int|string|WP_Post|null) post Optional. Post content, post ID, or post object. Defaults to global $post.
See:Returns:- (bool) Whether the post content contains the specified block.
Defined at: - Introduced in WordPress: 5.0.0
- Deprecated in WordPress: —
Description
Determines whether a $post or a string contains a specific block type.This test optimizes for performance rather than strict accuracy, detecting
whether the block type exists but not validating its structure and not checking
synced patterns (formerly called reusable blocks). For strict accuracy,
you should use the block parser on post content.