wp_get_script_tag() – Formats `<script>` loader tags.

Description

Formats <script> loader tags.

It is possible to inject attributes in the <script> tag via the wp_script_attributes filter. Automatically injects type attribute if needed.

Usage

$string = wp_get_script_tag( $attributes );

Parameters

$attributes
( array ) required – Key-value pairs representing <script> tag attributes.

Returns

string String containing <script> opening and closing tags.

Source

File name: wordpress/wp-includes/script-loader.php
Lines:

1 to 17 of 17
function wp_get_script_tag( $attributes ) {
  if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
    $attributes['type'] = 'text/javascript';
  }
  
/**
 * 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 on GitHub View on Trac

Invoked by

    Call hooks

    API Letters: ,,,