WP_Scripts::print_extra_script
Prints extra scripts of a registered script.
Method of the class: WP_Scripts{}
No Hooks.
Returns
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() WP Scripts::print extra script code WP 6.9.1
public function print_extra_script( $handle, $display = true ) {
$output = $this->get_data( $handle, 'data' );
if ( ! $output ) {
return;
}
/*
* Do not print a sourceURL comment if concatenation is enabled.
*
* Extra scripts may be concatenated into a single script.
* The line-based sourceURL comments may break concatenated scripts
* and do not make sense when multiple scripts are joined together.
*/
if ( ! $this->do_concat ) {
$output .= sprintf(
"\n//# sourceURL=%s",
rawurlencode( "{$handle}-js-extra" )
);
}
if ( ! $display ) {
return $output;
}
wp_print_inline_script_tag( $output, array( 'id' => "{$handle}-js-extra" ) );
return true;
}