[ WordPress.org  ](https://wordpress.org/)

  * [ News  ](https://wordpress.org/news/)
  * [ Showcase  ](https://wordpress.org/showcase/)
  * [ Hosting  ](https://wordpress.org/hosting/)
  * Extend 
    * [ Themes  ](https://wordpress.org/themes/)
    * [ Plugins  ](https://wordpress.org/plugins/)
    * [ Patterns  ](https://wordpress.org/patterns/)
    * [ Blocks  ](https://wordpress.org/blocks/)
    * [ Openverse  ↗  ︎  ](https://openverse.org/)
  * Learn 
    * [ Learn WordPress  ](https://learn.wordpress.org/)
    * [ Documentation  ](https://wordpress.org/documentation/)
    * [ Forums  ](https://wordpress.org/support/forums/)
    * [ Developers  ](https://developer.wordpress.org/)
    * [ WordPress.tv  ↗  ︎  ](https://wordpress.tv/)
  * Community 
    * [ Make WordPress  ](https://make.wordpress.org/)
    * [ Photo Directory  ](https://wordpress.org/photos/)
    * [ Five for the Future  ](https://wordpress.org/five-for-the-future/)
    * [ Events  ](https://events.wordpress.org/)
    * [ Job Board  ↗  ︎  ](https://jobs.wordpress.net/)
  * About 
    * [ About WordPress  ](https://wordpress.org/about/)
    * [ Enterprise  ](https://wordpress.org/enterprise/)
    * [ Gutenberg  ↗  ︎  ](https://wordpress.org/gutenberg/)
    * [ Swag Store  ↗  ︎  ](https://mercantile.wordpress.org/)
  * [ Get WordPress  ](https://wordpress.org/download/)

Search in WordPress.org

[ Get WordPress ](https://wordpress.org/download/)

[ WordPress.org  ](https://wordpress.org/)

[ WordPress Developer Resources ](https://developer.wordpress.org)

wp_get_inline_script_tag()

  * [ Developer Blog  ](https://developer.wordpress.org/news/)
  * [ Code Reference  ](https://developer.wordpress.org/reference/)
  * [ WP-CLI Commands  ](https://developer.wordpress.org/cli/commands/)

  * [ Developer Blog  ](https://developer.wordpress.org/news/)
  * [ Code Reference  ](https://developer.wordpress.org/reference/)
  * [ WP-CLI Commands  ](https://developer.wordpress.org/cli/commands/)

[ Home ](https://developer.wordpress.org) [ Reference
](https://developer.wordpress.org/reference/) [ Functions
](https://developer.wordpress.org/reference/functions/)
wp_get_inline_script_tag()

Search

#  wp_get_inline_script_tag(  string  $data  ,  array  $attributes  =  array()
):  string

##  In this article

Table of Contents

  * Description 
  * Parameters 
  * Return 
  * Source 
  * Hooks 
  * Related 
  * Changelog 
  * User Contributed Notes 

↑  Back to top

Constructs an inline script tag.

##  Description

It is possible to inject attributes in the ` <script> ` tag via the [
‘wp_script_attributes’
](https://developer.wordpress.org/reference/hooks/wp_script_attributes/)
filter.  
Automatically injects type attribute if needed.

##  Parameters

` $data ` string  required

    

Data for script tag: JavaScript, importmap, speculationrules, etc.

` $attributes ` array  optional

    

Key-value pairs representing ` <script> ` tag attributes.

Default: ` array() `

##  Return

string  String containing inline JavaScript code wrapped around ` <script> `
tag.

##  Source

    
    
    function wp_get_inline_script_tag( $data, $attributes = array() ) {
    	$is_html5 = current_theme_supports( 'html5', 'script' ) || is_admin();
    	if ( ! isset( $attributes['type'] ) && ! $is_html5 ) {
    		// Keep the type attribute as the first for legacy reasons (it has always been this way in core).
    		$attributes = array_merge(
    			array( 'type' => 'text/javascript' ),
    			$attributes
    		);
    	}
    
    	/*
    	 * XHTML extracts the contents of the SCRIPT element and then the XML parser
    	 * decodes character references and other syntax elements. This can lead to
    	 * misinterpretation of the script contents or invalid XHTML documents.
    	 *
    	 * Wrapping the contents in a CDATA section instructs the XML parser not to
    	 * transform the contents of the SCRIPT element before passing them to the
    	 * JavaScript engine.
    	 *
    	 * Example: