WP_Scripts::print_extra_script()publicWP 3.3.0

Prints extra scripts of a registered script.

Method of the class: WP_Scripts{}

No Hooks.

Return

true|false|String|null. Void if no data exists, extra scripts if $display is true, true otherwise.

Usage

global $wp_scripts;
$wp_scripts->print_extra_script( $handle, $display );
$handle(string) (required)
The script's registered handle.
$display(true|false)
Whether to print the extra script instead of just returning it.
Default: true

Changelog

Since 3.3.0 Introduced.

WP_Scripts::print_extra_script() code WP 6.1.1

public function print_extra_script( $handle, $display = true ) {
	$output = $this->get_data( $handle, 'data' );
	if ( ! $output ) {
		return;
	}

	if ( ! $display ) {
		return $output;
	}

	printf( "<script%s id='%s-js-extra'>\n", $this->type_attr, esc_attr( $handle ) );

	// CDATA is not needed for HTML 5.
	if ( $this->type_attr ) {
		echo "/* <![CDATA[ */\n";
	}

	echo "$output\n";

	if ( $this->type_attr ) {
		echo "/* ]]> */\n";
	}

	echo "</script>\n";

	return true;
}