WP_Scripts::add_inline_script()publicWP 4.5.0

Adds extra code to a registered script.

Method of the class: WP_Scripts{}

No Hooks.

Return

true|false. True on success, false on failure.

Usage

global $wp_scripts;
$wp_scripts->add_inline_script( $handle, $data, $position );
$handle(string) (required)
Name of the script to add the inline script to. Must be lowercase.
$data(string) (required)
String containing the JavaScript to be added.
$position(string)
Whether to add the inline script before the handle or after.
Default: 'after'

Changelog

Since 4.5.0 Introduced.

WP_Scripts::add_inline_script() code WP 6.5.2

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