Title: wp_get_first_block
Published: August 8, 2023
Last modified: April 28, 2025

---

# wp_get_first_block( array $blocks, string $block_name ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#wp--skip-link--target)

Finds the first occurrence of a specific block in an array of blocks.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#parameters)󠁿

 `$blocks`arrayrequired

Array of blocks.

`$block_name`stringrequired

Name of the block to find.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#return)󠁿

 array Found block, or empty array if none found.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#source)󠁿

    ```php
    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();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/block-editor.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/block-editor.php#L401)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/block-editor.php#L401-L416)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_first_block()](https://developer.wordpress.org/reference/functions/wp_get_first_block/)`wp-includes/block-editor.php` |

Finds the first occurrence of a specific block in an array of blocks.

  |

| Used by | Description | 
| [wp_get_first_block()](https://developer.wordpress.org/reference/functions/wp_get_first_block/)`wp-includes/block-editor.php` |

Finds the first occurrence of a specific block in an array of blocks.

  | 
| [wp_get_post_content_block_attributes()](https://developer.wordpress.org/reference/functions/wp_get_post_content_block_attributes/)`wp-includes/block-editor.php` |

Retrieves Post Content block attributes from the current post template.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_get_first_block/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_first_block%2F)
before being able to contribute a note or feedback.