WP_Scripts::print_inline_script()publicWP 4.5.0

Prints inline scripts registered for a specific handle.

Method of the class: WP_Scripts{}

No Hooks.


String|false. Script on success, false otherwise.


global $wp_scripts;
$wp_scripts->print_inline_script( $handle, $position, $display );
$handle(string) (required)
Name of the script to add the inline script to. Must be lowercase.
Whether to add the inline script before the handle or after.
Default: 'after'
Whether to print the script instead of just returning it.
Default: true


Since 4.5.0 Introduced.

WP_Scripts::print_inline_script() code WP 6.1.1

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;