WP_Scripts::print_inline_script() WordPress Method

The WP_Scripts::print_inline_script() method is used to print inline scripts that have been added to the $wp_scripts object.

WP_Scripts::print_inline_script( string $handle, string $position = 'after', bool $display = true ) #

Prints inline scripts registered for a specific handle.


Parameters

$handle

(string)(Required)Name of the script to add the inline script to. Must be lowercase.

$position

(string)(Optional) Whether to add the inline script before the handle or after.

Default value: 'after'

$display

(bool)(Optional) Whether to print the script instead of just returning it.

Default value: true


Top ↑

Return

(string|false) Script on success, false otherwise.


Top ↑

Source

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

	public function print_inline_script( $handle, $position = 'after', $display = true ) {
		$output = $this->get_data( $handle, $position );

		if ( empty( $output ) ) {
			return false;
		}

		$output = trim( implode( "\n", $output ), "\n" );

		if ( $display ) {
			printf( "<script%s id='%s-js-%s'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output );
		}

		return $output;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.