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
$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
Changelog
Version | Description |
---|---|
4.1.0 | Introduced. |
Useful when a script excecution depends on “ attributes, eg:
Scripts must be registered/enqueued via wp_enqueue_script()
It can be used to defer or async all JS scripts :
You can also use the
$handle
argument to filter scripts.