On this page
WP_Scripts::print_inline_script( string $handle, string $position = 'after', bool $display = true ): string|false
Prints inline scripts registered for a specific handle.
Parameters
$handlestring Required-
Name of the script to add the inline script to.
Must be lowercase. $positionstring Optional-
Whether to add the inline script before the handle or after. Default
'after'.Default:
'after' $displaybool Optional-
Whether to print the script instead of just returning it.
Default:
true
Return
string|false Script on success, false otherwise.
Source
File: wp-includes/class-wp-scripts.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
Used By
| Used By | Description |
|---|---|
| WP_Scripts::do_item() wp-includes/class-wp-scripts.php | Processes a script dependency. |
Changelog
| Version | Description |
|---|---|
| 4.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_scripts/print_inline_script