WP_Interactivity_API_Directives_Processor::get_content_between_balanced_template_tags()publicWP 6.5.0

Returns the content between two balanced template tags.

It positions the cursor in the closer tag of the balanced template tag, if it exists.

Method of the class: WP_Interactivity_API_Directives_Processor{}

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.


String|null. The content between the current opener template tag and its matching closer tag or null if it doesn't find the matching closing tag or the current tag is not a template opener tag.


$WP_Interactivity_API_Directives_Processor = new WP_Interactivity_API_Directives_Processor();


Since 6.5.0 Introduced.

WP_Interactivity_API_Directives_Processor::get_content_between_balanced_template_tags() code WP 6.6

public function get_content_between_balanced_template_tags() {
	if ( 'TEMPLATE' !== $this->get_tag() ) {
		return null;

	$positions = $this->get_after_opener_tag_and_before_closer_tag_positions();
	if ( ! $positions ) {
		return null;
	list( $after_opener_tag, $before_closer_tag ) = $positions;

	return substr( $this->html, $after_opener_tag, $before_closer_tag - $after_opener_tag );