Title: WP_HTML_Tag_Processor::get_tag
Published: March 29, 2023
Last modified: August 20, 2026

---

# WP_HTML_Tag_Processor::get_tag(): string|null

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#wp--skip-link--target)

Returns the uppercase name of the matched tag.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#description)󠁿

Example:

    ```php
    $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;
    ```

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#return)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#source)󠁿

    ```php
    public function get_tag(): ?string {
    	if ( null === $this->tag_name_starts_at ) {
    		return null;
    	}

    	$tag_name = str_replace( "\x00", "\u{FFFD}", substr( $this->html, $this->tag_name_starts_at, $this->tag_name_length ) );

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

    	/*
    	 * Processing instruction targets are case-sensitive
    	 * and returned as they appear in the input HTML.
    	 */
    	if ( self::STATE_PROCESSING_INSTRUCTION === $this->parser_state ) {
    		return $tag_name;
    	}

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

    	return null;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/html-api/class-wp-html-tag-processor.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/html-api/class-wp-html-tag-processor.php#L3047)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/html-api/class-wp-html-tag-processor.php#L3047-L3074)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_HTML_Tag_Processor::get_comment_type()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_comment_type/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Indicates what kind of comment produced the comment node.

  |

| Used by | Description | 
| [WP_HTML_Tag_Processor::get_qualified_tag_name()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_qualified_tag_name/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Returns the adjusted tag name for a given token, taking into account the current parsing context, whether HTML, SVG, or MathML.

  | 
| [WP_HTML_Tag_Processor::get_full_comment_text()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_full_comment_text/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Returns the text of a matched comment or null if not on a comment type node.

  | 
| [WP_HTML_Tag_Processor::set_modifiable_text()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/set_modifiable_text/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Sets the modifiable text for the matched token, if matched.

  | 
| [WP_HTML_Tag_Processor::get_token_name()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_token_name/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Returns the node name represented by the token.

  | 
| [WP_HTML_Processor::get_tag()](https://developer.wordpress.org/reference/classes/wp_html_processor/get_tag/)`wp-includes/html-api/class-wp-html-processor.php` |

Returns the uppercase name of the matched tag.

  | 
| [WP_HTML_Tag_Processor::is_tag_closer()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/is_tag_closer/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Indicates if the current tag token is a tag closer.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/get_tag/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_html_tag_processor%2Fget_tag%2F)
before being able to contribute a note or feedback.