apply_filters( 'script_loader_tag', string $tag , string $handle , string $src )
Filters the HTML script tag of an enqueued script.
Parameters
-
$tag
string -
The
<script>
tag for the enqueued script. -
$handle
string -
The script's registered handle.
-
$src
string -
The script's source URL.
Source
File: wp-includes/class-wp-scripts.php
.
View all references
$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
Changelog
Version | Description |
---|---|
4.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Useful when a script excecution depends on “ attributes, eg:
Top ↑
Feedback
Missing { on line 4. — By Sam Kent —
Is it possible to do with Array? I have several Scripts that I want to do this, can I just replicate this code by changing the scripts? An Array would be better, right? — By ofmarconi —
It can be used to defer or async all JS scripts :
You can also use the
$handle
argument to filter scripts.Top ↑
Feedback
To expand on Geoffrey Brossard’s note, you might run into issues deferring all, the example below you can exclude the handles you might need from this filter like so:
— By studiolxv —