WP_HTML_Processor::get_tag(): string|null

In this article

Returns the uppercase name of the matched tag.

Description

The semantic rules for HTML specify that certain tags be reprocessed with a different tag name. Because of this, the tag name presented by the HTML Processor may differ from the one reported by the HTML Tag Processor, which doesn’t apply these semantic rules.

Example:

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

$processor->next_tag() === false;
$processor->get_tag() === null;

Return

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

Source

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

	if ( $this->is_virtual() ) {
		return $this->current_element->token->node_name;
	}

	$tag_name = parent::get_tag();

	switch ( $tag_name ) {
		case 'IMAGE':
			/*
			 * > A start tag whose tag name is "image"
			 * > Change the token's tag name to "img" and reprocess it. (Don't ask.)
			 */
			return 'IMG';

		default:
			return $tag_name;
	}
}

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

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