wp_print_inline_script_tag( string $data, $attributes = array() )
- Since
- 5.7.0
- Source
wp-includes/script-loader.php:3079
Description
It is possible to inject attributes in the <script> tag via the 'wp_inline_script_attributes' filter.
Automatically injects type attribute if needed.
Compatibility
- WordPress
- since 5.7.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$datastring- Data for script tag: JavaScript, importmap, speculationrules, etc.
$attributesoptional- Default:
array()
Performance profile
How much work a call to wp_print_inline_script_tag() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 8
- Plugin surface
- None
- Called by
- 32
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 8.
Nothing here hands control to plugin code.
32 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_print_inline_script_tag()
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_print_inline_script_tag() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | wp_get_inline_script_tag() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 8 instructions, 8 executed per call, 0 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- wp_get_inline_script_tag()Constructs an inline script tag.
Used by · 32
- Twenty_Twenty_One_Dark_Mode::the_script()Prints the dark-mode switch script.
- WP_Customize_Manager::customize_pane_settings()Prints JavaScript settings for parent window.
- WP_Customize_Manager::customize_preview_settings()Prints JavaScript settings for preview frame.
- WP_Customize_Manager::remove_frameless_preview_messenger_channel()Removes customize_messenger_channel query parameter from the preview window when it is not in an iframe.
- WP_Customize_Nav_Menus::export_preview_data()Exports data from PHP to JS.
- WP_Customize_Selective_Refresh::export_preview_data()Exports data in preview after it has finished rendering so that partials can be added at runtime.
- WP_Customize_Widgets::export_preview_data()Communicates the sidebars that appeared on the page at the very end of the page, and at the very end of the wp_footer,
- WP_Script_Modules::print_import_map()Prints the import map using a script tag with a type="importmap" attribute.
- WP_Script_Modules::print_script_module_data()Print data associated with Script Modules.
- WP_Script_Modules::print_script_module_translations()Prints translations for all enqueued script modules.
- WP_Scripts::print_extra_script()Prints extra scripts of a registered script.
- WP_Scripts::print_translations()Prints translations set for a specific handle.
Show all 32
- WP_Widget_Archives::widget()Outputs the content for the current Archives widget instance.
- WP_Widget_Categories::widget()Outputs the content for the current Categories widget instance.
- _print_emoji_detection_script()Prints inline Emoji detection script.
- _print_scripts()Prints scripts (internal use only)
- login_footer()Outputs the footer for the login page.
- login_header()Outputs the login page header.
- print_embed_scripts()Prints the JavaScript in the embed iframe header.
- twenty_twenty_one_supports_js()Removes the `no-js` class from body if JS is supported.
- twentyfifteen_color_scheme_css_template()Outputs an Underscore template for generating CSS for the color scheme.
- twentyfifteen_javascript_detection()JavaScript Detection.
- twentyseventeen_javascript_detection()Handles JavaScript detection.
- twentysixteen_color_scheme_css_template()Outputs an Underscore template for generating CSS for the color scheme.
- twentysixteen_javascript_detection()Handles JavaScript detection.
- twentytwenty_no_js_class()Adds 'no-js' class.
- twentytwentyone_add_ie_class()Adds "is-IE" class to body if the user is on Internet Explorer.
- wp_comment_form_unfiltered_html_nonce()Displays form token for unfiltered comments.
- wp_customize_support_script()Prints a script to check whether or not the Customizer is supported, and apply either the no-customize-support or customize-support class to the body.
- wp_post_preview_js()Outputs a small JS snippet on preview tabs/windows to remove `window.name` when a user is navigating to another page.
- wp_print_speculation_rules()Prints the speculation rules.
- wp_shake_js()Outputs the JavaScript to handle the form shaking on the login page.
Source code
function wp_print_inline_script_tag( $data, $attributes = array() ) { echo wp_get_inline_script_tag( $data, $attributes );}Changelog
Introduced in 5.7.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$attributes retyped from array to untyped.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/script-loader.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.