WP_HTML_Tag_Processor::next_tag( array|string|null $query = null ): bool

In this article

Finds the next tag matching the $query.

Parameters

$queryarray|string|nulloptional
Which tag name to find, having which class, etc. Default is to find any tag.
  • tag_name string|null
    Which tag to find, or null for "any tag."
  • match_offset int|null
    Find the Nth tag matching all search criteria.
    1 for "first" tag, 3 for "third," etc.
    Defaults to first tag.
  • class_name string|null
    Tag must contain this whole class name to match.
  • tag_closers string|null
    "visit" or "skip": whether to stop on tag closers, e.g. </div>.

Default:null

Return

bool Whether a tag was matched.

Source

public function next_tag( $query = null ) {
	$this->parse_query( $query );
	$already_found = 0;

	do {
		if ( false === $this->next_token() ) {
			return false;
		}

		if ( self::STATE_MATCHED_TAG !== $this->parser_state ) {
			continue;
		}

		if ( $this->matches() ) {
			++$already_found;
		}
	} while ( $already_found < $this->sought_match_offset );

	return true;
}

Changelog

VersionDescription
6.5.0No longer processes incomplete tokens at end of document; pauses the processor at start of token.
6.2.0Introduced.

User Contributed Notes

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