apply_filters( ‘hooked_block_types’, string[] $hooked_block_types, string $relative_position, string $anchor_block_type, WP_Block_Template|WP_Post|array $context )

Filters the list of hooked block types for a given anchor block type and relative position.

Parameters

$hooked_block_typesstring[]
The list of hooked block types.
$relative_positionstring
The relative position of the hooked blocks.
Can be one of 'before', 'after', 'first_child', or 'last_child'.
$anchor_block_typestring
The anchor block type.
$contextWP_Block_Template|WP_Post|array
The block template, template part, post object, or pattern that the anchor block belongs to.

Source

$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    The following example will insert a custom block after after heading block:

    /**
     * Use block hooks to inject the custom block after the heading block
     *
     * @param string                          $hooked_blocks The list of hooked block types.
     * @param string                          $position The relative position of the hooked blocks. Values: 'before', 'after', 'first_child', or 'last_child'.
     * @param string                          $anchor_block The anchor block type.
     * @param WP_Block_Template|WP_Post|array $context The block template, template part, post object, or pattern that the anchor block belongs to.
     * @return string
     */
    function hook_custom_text_after_block( $hooked_blocks, $position, $anchor_block, $context ) {
    	// Check if we're in the 'after' position.
    	if ( $position !== 'after' ) {
    		return $hooked_blocks;
    	}
    	
    	// Check if the anchor block is the heading block.
    	if ( $anchor_block !== 'core/heading' ) {
    		return $hooked_blocks;
    	}
    	
    	// Add our custom block to be hooked after heading block.
    	$hooked_blocks[] = 'custom/flash-text';
    	
    	return $hooked_blocks;
    }
    add_filter( 'hooked_block_types', 'hook_custom_text_after_block', 10, 4 );

You must log in before being able to contribute a note or feedback.