Title: WP_HTML_Processor::has_self_closing_flag
Published: July 16, 2024
Last modified: February 24, 2026

---

# WP_HTML_Processor::has_self_closing_flag(): bool

## In this article

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

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

Indicates if the currently matched tag contains the self-closing flag.

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

No HTML elements ought to have the self-closing flag and for those, the self-closing
flag will be ignored. For void elements this is benign because they “self close”
automatically. For non-void HTML elements though problems will appear if someone
intends to use a self-closing element in place of that element with an empty body.

For HTML foreign elements and custom elements the self-closing flag determines if
they self-close or not.

This function does not determine if a tag is self-closing, but only if the self-
closing flag is present in the syntax.

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

 bool Whether the currently matched tag contains the self-closing flag.

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

    ```php
    public function has_self_closing_flag(): bool {
    	return $this->is_virtual() ? false : parent::has_self_closing_flag();
    }
    ```

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

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

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

Indicates if the currently-matched token is virtual, created by a stack operation while processing HTML, rather than a token found in the HTML text itself.

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

Indicates if the currently matched tag contains the self-closing flag.

  |

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

Serializes the currently-matched token.

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

Indicates if the currently-matched node expects a closing token, or if it will self-close on the next step.

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

Steps through the HTML document and stop at the next tag, if any.

  |

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

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.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_processor%2Fhas_self_closing_flag%2F)
before being able to contribute a note or feedback.