apply_filters( 'script_loader_tag', string $tag, string $handle, string $src )

Filters the HTML script tag of an enqueued script.

Description Description

Parameters Parameters


(string) The <script> tag for the enqueued script.


(string) The script's registered handle.


(string) The script's source URL.

Top ↑

Source Source

File: wp-includes/class.wp-scripts.php

View on Trac

Top ↑

Changelog Changelog

Version Description
4.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by opportus

    Useful when a script excecution depends on “ attributes, eg:

    add_filter( 'script_loader_tag', 'add_id_to_script', 10, 3 );
    function add_id_to_script( $tag, $handle, $src ) {
        if ( 'dropbox.js' === $handle ) {
            $tag = '<script type="text/javascript" src="' . esc_url( $src ) . '" id="dropboxjs" data-app-key="MY_APP_KEY"></script>';
        return $tag;

You must log in before being able to contribute a note or feedback.