Filters attributes to be added to a script tag.
Parameters
$attributes
array- 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.
Source
$attributes = apply_filters( 'wp_script_attributes', $attributes );
Changelog
Version | Description |
---|---|
5.7.0 | Introduced. |
If you want to harden your website against supply chain attacks, you can use this filter to add Subresource integrity checking to a script.
For example, for Select2 script at v4.0.9 from cdnjs.com, you would copy the SRI hash from https://cdnjs.com/libraries/select2/4.0.9, and add it as an attribute to the script.
Then check for the select2-js ID, and that it is delivered by CDNJS, before adding the SRI attributes.