apply_filters( 'wp_inline_script_attributes', array $attributes , string $javascript )
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. -
$javascript
string -
Inline JavaScript code.
Source
File: wp-includes/script-loader.php
.
View all references
$attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript );
Changelog
Version | Description |
---|---|
5.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
This has to be used to make WP a CSP compliant system (at least, in the front end. Remains to be tested in the admin area)
Then, you can use
'nonce-123'
in your CSP Policy, example:"script-src 'self' 'noncoe-123';"
Top ↑
Feedback
Note that this will override other attributes on the script tag. Would be better to set
$attr[‘nonce’]
on the existing array rather than return a new array. — By crstauf —