WP_Interactivity_API_Directives_Processor::next_balanced_tag_closer_tag()publicWP 6.5.0

Finds the matching closing tag for an opening tag.

When called while the processor is on an open tag, it traverses the HTML until it finds the matching closer tag, respecting any in-between content, including nested tags of the same name. Returns false when called on a closer tag, a tag that doesn't have a closer tag (void), a tag that doesn't visit the closer tag, or if no matching closing tag was found.

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.


true|false. Whether a matching closing tag was found.


$WP_Interactivity_API_Directives_Processor = new WP_Interactivity_API_Directives_Processor();
$WP_Interactivity_API_Directives_Processor->next_balanced_tag_closer_tag(): bool;


Since 6.5.0 Introduced.

WP_Interactivity_API_Directives_Processor::next_balanced_tag_closer_tag() code WP 6.5.4

public function next_balanced_tag_closer_tag(): bool {
	$depth    = 0;
	$tag_name = $this->get_tag();

	if ( ! $this->has_and_visits_its_closer_tag() ) {
		return false;

	while ( $this->next_tag(
			'tag_name'    => $tag_name,
			'tag_closers' => 'visit',
	) ) {
		if ( ! $this->is_tag_closer() ) {

		if ( 0 === $depth ) {
			return true;


	return false;