apply_block_hooks_to_content( string $content, WP_Block_Template|WP_Post|array $context, callable $callback = ‘insert_hooked_blocks’ ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Runs the hooked blocks algorithm on the given content.

Parameters

$contentstringrequired
Serialized content.
$contextWP_Block_Template|WP_Post|arrayrequired
A block template, template part, wp_navigation post object, or pattern that the blocks belong to.
$callbackcallableoptional
A function that will be called for each block to generate the markup for a given list of blocks that are hooked to it.
Default: 'insert_hooked_blocks'.

Default:'insert_hooked_blocks'

Return

string The serialized markup.

Source

function apply_block_hooks_to_content( $content, $context, $callback = 'insert_hooked_blocks' ) {
	$hooked_blocks = get_hooked_blocks();
	if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) {
		return $content;
	}

	$blocks = parse_blocks( $content );

	$before_block_visitor = make_before_block_visitor( $hooked_blocks, $context, $callback );
	$after_block_visitor  = make_after_block_visitor( $hooked_blocks, $context, $callback );

	return traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
}

Changelog

VersionDescription
6.6.0Introduced.

User Contributed Notes

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