WP_Scripts::print_inline_script()
Prints inline scripts registered for a specific handle.
Method of the class: WP_Scripts{}
No Hooks.
Return
String|false
. Script on success, false otherwise.
Usage
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.
- $position(string)
- Whether to add the inline script before the handle or after.
Default: 'after' - $display(true|false)
- Whether to print the script instead of just returning it.
Default: true
Changelog
Since 4.5.0 | Introduced. |
WP_Scripts::print_inline_script() 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; }