wp_get_first_block()
Finds the first occurrence of a specific block in an array of blocks.
No Hooks.
Return
Array
. Found block, or empty array if none found.
Usage
wp_get_first_block( $blocks, $block_name );
- $blocks(array) (required)
- Array of blocks.
- $block_name(string) (required)
- Name of the block to find.
Changelog
Since 6.3.0 | Introduced. |
wp_get_first_block() wp get first block code WP 6.7.1
function wp_get_first_block( $blocks, $block_name ) { foreach ( $blocks as $block ) { if ( $block_name === $block['blockName'] ) { return $block; } if ( ! empty( $block['innerBlocks'] ) ) { $found_block = wp_get_first_block( $block['innerBlocks'], $block_name ); if ( ! empty( $found_block ) ) { return $found_block; } } } return array(); }