# wp_add_inline_script()

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

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

## Сигнатура

```php
wp_add_inline_script( string $handle, string $data, string $position = 'after' ): bool
```

## Описание

Code will only be added if the script is already in the queue.
Accepts a string `$data` containing the code. If two or more code blocks are added to the same script `$handle`, they will be printed in the order they were added, i.e. the latter added code can redeclare the previous.[See also](#see-also)
- [WP_Scripts::add_inline_script()](https://developer.wordpress.org/reference/classes/WP_Scripts/add_inline_script/)

## Параметры

- `$handle` `string` — обязательный. Имя скрипта, к которому добавляется встроенный скрипт.
- `$data` `string` — обязательный. Строка с JavaScript-кодом, который нужно добавить.
- `$position` `string` — необязательный, по умолчанию `'after'`. Добавлять ли встроенный скрипт до или после дескриптора. Значение по умолчанию 'after'.

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

`bool`

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

Файл: `wp-includes/functions-wp-scripts.php:210`

```php
function wp_add_inline_script( $handle, $data, $position = 'after' ) {
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );

	if ( false !== stripos( $data, '</script>' ) ) {
		_doing_it_wrong(
			__FUNCTION__,
			sprintf(
				/* translators: 1: <script>, 2: wp_add_inline_script() */
				__( 'Do not pass %1$s tags to %2$s.' ),
				'<code>&lt;script&gt;</code>',
				'<code>wp_add_inline_script()</code>'
			),
			'4.5.0'
		);
		$data = trim( (string) preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) );
	}

	return wp_scripts()->add_inline_script( $handle, $data, $position );
}
```

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

- 4.5.0 — Introduced.

## Связанные

Использует: [`stripos`](https://chugunov.pro/api-wordpress/functions/stripos/), `WP_Scripts::add_inline_script`, [`wp_scripts`](https://chugunov.pro/api-wordpress/functions/wp_scripts/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`_doing_it_wrong`](https://chugunov.pro/api-wordpress/functions/_doing_it_wrong/).
Используется в: [`wp_collaboration_inject_setting`](https://chugunov.pro/api-wordpress/functions/wp_collaboration_inject_setting/), [`wp_options_connectors_wp_admin_preload_data`](https://chugunov.pro/api-wordpress/functions/wp_options_connectors_wp_admin_preload_data/), [`wp_options_connectors_wp_admin_enqueue_scripts`](https://chugunov.pro/api-wordpress/functions/wp_options_connectors_wp_admin_enqueue_scripts/), [`wp_options_connectors_preload_data`](https://chugunov.pro/api-wordpress/functions/wp_options_connectors_preload_data/), [`wp_options_connectors_render_page`](https://chugunov.pro/api-wordpress/functions/wp_options_connectors_render_page/), [`wp_font_library_render_page`](https://chugunov.pro/api-wordpress/functions/wp_font_library_render_page/), [`wp_font_library_wp_admin_preload_data`](https://chugunov.pro/api-wordpress/functions/wp_font_library_wp_admin_preload_data/), [`wp_font_library_wp_admin_enqueue_scripts`](https://chugunov.pro/api-wordpress/functions/wp_font_library_wp_admin_enqueue_scripts/), [`wp_font_library_preload_data`](https://chugunov.pro/api-wordpress/functions/wp_font_library_preload_data/), [`_wp_enqueue_auto_register_blocks`](https://chugunov.pro/api-wordpress/functions/_wp_enqueue_auto_register_blocks/), [`wp_enqueue_command_palette_assets`](https://chugunov.pro/api-wordpress/functions/wp_enqueue_command_palette_assets/), [`wp_attach_theme_preview_middleware`](https://chugunov.pro/api-wordpress/functions/wp_attach_theme_preview_middleware/), [`block_editor_rest_api_preload`](https://chugunov.pro/api-wordpress/functions/block_editor_rest_api_preload/), [`enqueue_editor_block_styles_assets`](https://chugunov.pro/api-wordpress/functions/enqueue_editor_block_styles_assets/), [`the_block_editor_meta_boxes`](https://chugunov.pro/api-wordpress/functions/the_block_editor_meta_boxes/), `WP_Privacy_Policy_Content::notice`, [`wp_enqueue_code_editor`](https://chugunov.pro/api-wordpress/functions/wp_enqueue_code_editor/), `WP_Widget_Media_Gallery::enqueue_admin_scripts`, `WP_Widget_Custom_HTML::enqueue_admin_scripts`, `WP_Widget_Text::enqueue_admin_scripts`, `WP_Widget_Media_Audio::enqueue_admin_scripts`, `WP_Widget_Media_Video::enqueue_admin_scripts`, `WP_Widget_Media_Image::enqueue_admin_scripts`, [`wp_localize_jquery_ui_datepicker`](https://chugunov.pro/api-wordpress/functions/wp_localize_jquery_ui_datepicker/), `WP_Customize_Widgets::enqueue_scripts`.

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