# wp_get_inline_script_tag()

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

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

## Сигнатура

```php
wp_get_inline_script_tag( string $data, $attributes = array() ): string
```

## Описание

В тег " );' );

// Эти данные небезопасны, и `text/plain` нельзя экранировать.
// Следующий вызов вернёт `""` , указывая на неудачу:
wp_get_inline_script_tag( '', array( 'type' => 'text/plain' ) );

## Параметры

- `$data` `string` — обязательный. Данные для тега script: JavaScript, importmap, speculationrules и т. д.

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

`string` — ""

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

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

```php
function wp_get_inline_script_tag( $data, $attributes = array() ) {
	$data = "\n" . trim( $data, "\n\r " ) . "\n";

	/**
	 * Filters attributes to be added to a script tag.
	 *
	 * @since 5.7.0
	 *
	 * @param array<string, string|bool> $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.
	 * @param string                     $data       Inline data.
	 */
	$attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $data );

	$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 );
	}

	if ( ! $processor->set_modifiable_text( $data ) ) {
		_doing_it_wrong(
			__FUNCTION__,
			__( 'Unable to set inline script data.' ),
			'7.0.0'
		);
		return '';
	}

	return "{$processor->get_updated_html()}\n";
}
```

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

- 7.0.0 — Returns an empty string if the data cannot be safely embedded in a script tag.
- 5.7.0 — Introduced.

## Связанные

Использует: `WP_HTML_Tag_Processor::__construct`, [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`_doing_it_wrong`](https://chugunov.pro/api-wordpress/functions/_doing_it_wrong/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`wp_admin_bar_command_palette_menu`](https://chugunov.pro/api-wordpress/functions/wp_admin_bar_command_palette_menu/), `WP_Scripts::get_inline_script_tag`, [`wp_print_inline_script_tag`](https://chugunov.pro/api-wordpress/functions/wp_print_inline_script_tag/), [`get_post_embed_html`](https://chugunov.pro/api-wordpress/functions/get_post_embed_html/), `WP_Customize_Manager::wp_die`, `WP_Scripts::do_item`.

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