Title: get_hooked_blocks
Published: November 8, 2023
Last modified: February 24, 2026

---

# get_hooked_blocks(): array[]

## In this article

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

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

Retrieves block types hooked into the given block, grouped by anchor block type 
and the relative position.

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

 array[] Array of block types grouped by anchor block type and the relative position.

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

    ```php
    function get_hooked_blocks() {
    	$block_types   = WP_Block_Type_Registry::get_instance()->get_all_registered();
    	$hooked_blocks = array();
    	foreach ( $block_types as $block_type ) {
    		if ( ! ( $block_type instanceof WP_Block_Type ) || ! is_array( $block_type->block_hooks ) ) {
    			continue;
    		}
    		foreach ( $block_type->block_hooks as $anchor_block_type => $relative_position ) {
    			if ( ! isset( $hooked_blocks[ $anchor_block_type ] ) ) {
    				$hooked_blocks[ $anchor_block_type ] = array();
    			}
    			if ( ! isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) ) {
    				$hooked_blocks[ $anchor_block_type ][ $relative_position ] = array();
    			}
    			$hooked_blocks[ $anchor_block_type ][ $relative_position ][] = $block_type->name;
    		}
    	}

    	return $hooked_blocks;
    }
    ```

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

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

| Uses | Description | 
| [WP_Block_Type_Registry::get_instance()](https://developer.wordpress.org/reference/classes/wp_block_type_registry/get_instance/)`wp-includes/class-wp-block-type-registry.php` |

Utility method to retrieve the main instance of the class.

  |

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

Runs the hooked blocks algorithm on the given content.

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

Inject ignoredHookedBlocks metadata attributes into a template or template part.

  | 
| [WP_Block_Patterns_Registry::get_all_registered()](https://developer.wordpress.org/reference/classes/wp_block_patterns_registry/get_all_registered/)`wp-includes/class-wp-block-patterns-registry.php` |

Retrieves all registered block patterns.

  |

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

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

## User Contributed Notes

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