WP_HTML_Tag_Processor::get_tag()publicWP 6.2.0

Returns the uppercase name of the matched tag.

Example:

$p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
$p->next_tag() === true;
$p->get_tag() === 'DIV';
$p->next_tag() === false;
$p->get_tag() === null;

Method of the class: WP_HTML_Tag_Processor{}

No Hooks.

Return

String|null. Name of currently matched tag in input HTML, or null if none found.

Usage

$WP_HTML_Tag_Processor = new WP_HTML_Tag_Processor();
$WP_HTML_Tag_Processor->get_tag();

Changelog

Since 6.2.0 Introduced.

WP_HTML_Tag_Processor::get_tag() code WP 6.6.2

public function get_tag() {
	if ( null === $this->tag_name_starts_at ) {
		return null;
	}

	$tag_name = substr( $this->html, $this->tag_name_starts_at, $this->tag_name_length );

	if ( self::STATE_MATCHED_TAG === $this->parser_state ) {
		return strtoupper( $tag_name );
	}

	if (
		self::STATE_COMMENT === $this->parser_state &&
		self::COMMENT_AS_PI_NODE_LOOKALIKE === $this->get_comment_type()
	) {
		return $tag_name;
	}

	return null;
}