WP_Scripts::add_inline_script

Advertisement

Summery Summery

Adds extra code to a registered script.

Syntax Syntax

WP_Scripts::add_inline_script( string $handle, string $data, string $position = 'after' )

Parameters Parameters

$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) (Optional) Whether to add the inline script before the handle or after.

Default value: 'after'

Return Return

(bool) True on success, false on failure.

Source Source

File: wp-includes/class.wp-scripts.php

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

Advertisement

Changelog Changelog

Changelog
Version Description
4.5.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.