On this page
WP_Scripts::add_inline_script( string $handle, string $data, string $position = 'after' ): bool
Adds extra code to a registered script.
Parameters
$handlestring Required-
Name of the script to add the inline script to.
Must be lowercase. $datastring Required-
String containing the JavaScript to be added.
$positionstring Optional-
Whether to add the inline script before the handle or after. Default
'after'.Default:
'after'
Return
bool True on success, false on failure.
Source
File: wp-includes/class-wp-scripts.php. View all references
public function add_inline_script( $handle, $data, $position = 'after' ) {
if ( ! $data ) {
return false;
}
if ( 'after' !== $position ) {
$position = 'before';
}
$script = (array) $this->get_data( $handle, $position );
$script[] = $data;
return $this->add_data( $handle, $position, $script );
}
Related
Used By
| Used By | Description |
|---|---|
| wp_tinymce_inline_scripts() wp-includes/script-loader.php | Adds inline scripts required for the TinyMCE in the block editor. |
| wp_add_inline_script() wp-includes/functions.wp-scripts.php | Adds extra code to a registered script. |
Changelog
| Version | Description |
|---|---|
| 4.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/WP_Scripts/add_inline_script