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

Prints inline scripts registered for a specific handle.


Parameters 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'

$echo

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

Default value: true


Top ↑

Return Return

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


Top ↑

Source Source

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

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

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

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

		if ( $echo ) {
			printf( "<script%s>\n%s\n</script>\n", $this->type_attr, $output );
		}

		return $output;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.