Title: esc_xml
Published: August 11, 2020
Last modified: February 24, 2026

---

# apply_filters( ‘esc_xml’, string $safe_text, string $text )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/esc_xml/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/esc_xml/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/esc_xml/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/esc_xml/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/esc_xml/?output_format=md#changelog)

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

Filters a string cleaned and escaped for output in XML.

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

Text passed to [esc_xml()](https://developer.wordpress.org/reference/functions/esc_xml/)
is stripped of invalid or special characters before output. HTML named character
references are converted to their equivalent code points.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/esc_xml/?output_format=md#parameters)󠁿

 `$safe_text`string

The text after it has been escaped.

`$text`string

The text prior to being escaped.

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

    ```php
    return apply_filters( 'esc_xml', $safe_text, $text );
    ```

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

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

| Used by | Description | 
| [esc_xml()](https://developer.wordpress.org/reference/functions/esc_xml/)`wp-includes/formatting.php` |

Escaping for XML blocks.

  |

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

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

## User Contributed Notes

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