WP_Scripts::get_inline_script_data() – Method | Developer.WordPress.org
Gets data for inline scripts registered for a specific handle.
Parameters
$handlestringrequiredName of the script to get data for.
Must be lowercase.$positionstringoptionalWhether to add the inline script before the handle or after. Default
'after'.
Return
string Inline script, which may be empty string.Source
public function get_inline_script_data( $handle, $position = 'after' ) {
$data = $this->get_data( $handle, $position );
if ( empty( $data ) || ! is_array( $data ) ) {
return '';
}
/*
* Print sourceURL comment regardless of concatenation.
*
* Inline scripts prevent scripts from being concatenated, so
* sourceURL comments are safe to print for inline scripts.
*/
$data[] = sprintf(
'//# sourceURL=%s',
rawurlencode( "{$handle}-js-{$position}" )
);
return trim( implode( "\n", $data ), "\n" );
}
Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |