# tag_escape()

URL: https://chugunov.pro/api-wordpress/functions/tag_escape/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.5.0.

## Сигнатура

```php
tag_escape( string $tag_name ): string
```

## Описание

Экранирует имя HTML-тега.

## Параметры

- `$tag_name` `string` — обязательный

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/formatting.php:4809`

```php
function tag_escape( $tag_name ) {
	$safe_tag = strtolower( preg_replace( '/[^a-zA-Z0-9-_:]/', '', $tag_name ) );
	/**
	 * Filters a string cleaned and escaped for output as an HTML tag.
	 *
	 * @since 2.8.0
	 *
	 * @param string $safe_tag The tag name after it has been escaped.
	 * @param string $tag_name The text before it was escaped.
	 */
	return apply_filters( 'tag_escape', $safe_tag, $tag_name );
}
```

## История изменений

- 6.5.5 — Allow hyphens in tag names (i.e. custom elements).
- 2.5.0 — Introduced.

## Связанные

Использует: [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`get_tag_regex`](https://chugunov.pro/api-wordpress/functions/get_tag_regex/), [`gallery_shortcode`](https://chugunov.pro/api-wordpress/functions/gallery_shortcode/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/tag_escape/
