Title: make_after_block_visitor
Published: November 8, 2023
Last modified: May 20, 2026

---

# make_after_block_visitor( array $hooked_blocks, WP_Block_Template|WP_Post|array $context, callable $callback = 'insert_hooked_blocks' ): callable

## In this article

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

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

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

Returns a function that injects the hooked blocks after a given block.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/make_after_block_visitor/?output_format=md#description)󠁿

The returned function can be used as `$post_callback` argument to `traverse_and_serialize_block(
s)`, where it will append the markup for any blocks hooked `after` the given block
and as its parent’s `last_child`, respectively.

This function is meant for internal use only.

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

 `$hooked_blocks`arrayrequired

An array of blocks hooked to another block.

`$context`[WP_Block_Template](https://developer.wordpress.org/reference/classes/wp_block_template/)
|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|arrayrequired

A block template, template part, post object, or pattern that the blocks belong 
to.

`$callback`callableoptional

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](https://developer.wordpress.org/reference/functions/make_after_block_visitor/?output_format=md#return)󠁿

 callable A function that returns the serialized markup for the given block, including
the markup for any hooked blocks after it.

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

    ```php
    function make_after_block_visitor( $hooked_blocks, $context, $callback = 'insert_hooked_blocks' ) {
    	/**
    	 * Injects hooked blocks after the given block, and returns the serialized markup.
    	 *
    	 * Append the markup for any blocks hooked `after` the given block and as its parent's
    	 * `last_child`, respectively, to the serialized markup for the given block.
    	 *
    	 * @param array $block        The block to inject the hooked blocks after. Passed by reference.
    	 * @param array $parent_block The parent block of the given block. Passed by reference. Default null.
    	 * @param array $next         The next sibling block of the given block. Default null.
    	 * @return string The serialized markup for the given block, with the markup for any hooked blocks appended to it.
    	 */
    	return function ( &$block, &$parent_block = null, $next = null ) use ( $hooked_blocks, $context, $callback ) {
    		$markup = call_user_func_array(
    			$callback,
    			array( &$block, 'after', $hooked_blocks, $context )
    		);

    		if ( $parent_block && ! $next ) {
    			// Candidate for last-child insertion.
    			$markup .= call_user_func_array(
    				$callback,
    				array( &$parent_block, 'last_child', $hooked_blocks, $context )
    			);
    		}

    		return $markup;
    	};
    }
    ```

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

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

| 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.

  |

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

| Version | Description | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | Added $callback argument. | 
| [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%2Fmake_after_block_visitor%2F)
before being able to contribute a note or feedback.