[ 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_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_script_tag()

Search

#  wp_get_script_tag(  array  $attributes  ):  string

##  In this article

Table of Contents

  * Description 
  * Parameters 
  * Return 
  * Source 
  * Hooks 
  * Related 
  * Changelog 

↑  Back to top

Formats ` ` loader tags.

##  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

` $attributes ` array  required

    

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

##  Return

string  String containing ` <script> ` opening and closing tags.

##  Source

    
    
    function wp_get_script_tag( $attributes ) {
    	if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
    		// 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
    		);
    	}
    	/**
    	 * Filters attributes to be added to a script tag.
    	 *
    	 * @since 5.7.0
    	 *
    	 * @param array $attributes Key-value pairs representing `<script>` tag attributes.
    	 *                          Only the attribute name is added to the `<script>` tag for
    	 *                          entries with a boolean value, and that are true.
    	 */
    	$attributes = apply_filters( 'wp_script_attributes', $attributes );
    
    	return sprintf( "<script%s></script>\n", wp_sanitize_script_attributes( $attributes ) );
    }
    

[ View all references ](https://developer.wordpress.org/reference/files/wp-
includes/script-loader.php/) [ View on Trac
](https://core.trac.wordpress.org/browser/tags/6.5/src/wp-includes/script-
load