Title: wp_kses_xml_named_entities
Published: August 11, 2020
Last modified: May 20, 2026

---

# wp_kses_xml_named_entities( array $matches ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_kses_xml_named_entities/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_kses_xml_named_entities/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_kses_xml_named_entities/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_kses_xml_named_entities/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_kses_xml_named_entities/?output_format=md#changelog)

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

Callback for `wp_kses_normalize_entities()` regular expression.

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

This function only accepts valid named entity references, which are finite, case-
sensitive, and highly scrutinized by XML validators. HTML named entity references
are converted to their code points.

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

 `$matches`arrayrequired

preg_replace_callback() matches array.

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

 string Correctly encoded entity.

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

    ```php
    function wp_kses_xml_named_entities( $matches ) {
    	global $allowedentitynames, $allowedxmlentitynames;

    	if ( empty( $matches[1] ) ) {
    		return '';
    	}

    	$i = $matches[1];

    	if ( in_array( $i, $allowedxmlentitynames, true ) ) {
    		return "&$i;";
    	} elseif ( in_array( $i, $allowedentitynames, true ) ) {
    		return html_entity_decode( "&$i;", ENT_HTML5 );
    	}

    	return "&amp;$i;";
    }
    ```

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

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_kses_xml_named_entities/?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%2Ffunctions%2Fwp_kses_xml_named_entities%2F)
before being able to contribute a note or feedback.