I\'m trying to use the wp_register_script and wp_enqueue_script FUNCTION on WordPress to enqueue a script, which has two attributes: \"integrity\" and \"crossorigin\".
N
This is well explained here:
For each enqueued script you need to add a filter which adds proper attributes;
/**
* load custom JS
*/
add_action('wp_enqueue_scripts', function() {
wp_enqueue_style('jquery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js', [], null);
add_filter('style_loader_tag', __NAMESPACE__ . '\\add_jquery_sri', 10, 2);
});
/**
* add SRI attributes to jQuery style loader element
* @param string $html
* @param string $handle
* @return string
*/
function add_jquery_sri($html, $handle) {
if ($handle === 'jQuery') {
$html = str_replace(' />', ' integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous" />', $html);
}
return $html;
}
URL & hash taken from https://cdnjs.com/libraries/jquery All praise to the authors!