# wp_get_script_tag()

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

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

## Сигнатура

```php
wp_get_script_tag( $attributes ): string
```

## Описание

В тег можно внедрить атрибуты с помощью фильтра ‘wp_script_attributes’.
При необходимости автоматически добавляет атрибут type.

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

`string` — 

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

Файл: `wp-includes/script-loader.php:2931`

```php
function wp_get_script_tag( $attributes ) {
	/**
	 * Filters attributes to be added to a script tag.
	 *
	 * @since 5.7.0
	 *
	 * @param array $attributes Key-value pairs representing `<script>` tag attributes.
	 *                          Only the attribute name is added to the `<script>` tag for
	 *                          entries with a boolean value, and that are true.
	 */
	$attributes = apply_filters( 'wp_script_attributes', $attributes );

	$processor = new WP_HTML_Tag_Processor( '<script></script>' );
	$processor->next_tag();
	foreach ( $attributes as $name => $value ) {
		/*
		 * Lexical variations of an attribute name may represent the
		 * same attribute in HTML, therefore it’s possible that the
		 * input array might contain duplicate attributes even though
		 * it’s keyed on their name. Calling code should rewrite an
		 * attribute’s value rather than sending a duplicate attribute.
		 *
		 * Example:
		 *
		 *     array( 'id' => 'main', 'ID' => 'nav' )
		 *
		 * In this example, there are two keys both describing the `id`
		 * attribute. PHP array iteration is in key-insertion order so
		 * the 'id' value will be set in the SCRIPT tag.
		 */
		if ( null !== $processor->get_attribute( $name ) ) {
			continue;
		}

		$processor->set_attribute( $name, $value ?? true );
	}
	return "{$processor->get_updated_html()}\n";
}
```

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

- 5.7.0 — Introduced.

## Связанные

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

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