apply_block_hooks_to_content()
Runs the hooked blocks algorithm on the given content.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Return
String
. The serialized markup.
Usage
apply_block_hooks_to_content( $content, $context, $callback );
- $content(string) (required)
- Serialized content.
- $context(WP_Block_Template|WP_Post|array) (required)
- A block template, template part, wp_navigation post object, or pattern that the blocks belong to.
- $callback(callable)
- 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'
Changelog
Since 6.6.0 | Introduced. |
apply_block_hooks_to_content() apply block hooks to content code WP 6.6.2
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 ); }