1

I'm using a function to call the css library for font awesome, I'd like to include the integrity key to make sure the file is secure.

integrity="sha384-xxx" crossorigin="anonymous"

Would something like the following work?

function jsScripts() {

$integrity = 'integrity="sha384-xxx"';
$crossorigin = 'crossorigin="anonymous"';

      wp_enqueue_script( 'fontawesome', 'https://use.fontawesome.com/releases/v5.5.0/css/all.css', $integrity, $crossorigin );

    }

    add_action('wp_enqueue_scripts','jsScripts');
GibsonFX
  • 1,000
  • 2
  • 10
  • 33

1 Answers1

2

You can do this using wp_script_add_data

https://developer.wordpress.org/reference/functions/wp_script_add_data/

Here's an example.

https://hotexamples.com/examples/-/-/wp_script_add_data/php-wp_script_add_data-function-examples.html

Please refer the following answer for more options.

Wordpress script with integrity and crossorigin

Jay Bhatt
  • 5,601
  • 5
  • 40
  • 62
  • Awesome, Thank you :) – GibsonFX Dec 03 '18 at 02:49
  • Also consider the forthcoming official Font Awesome WordPress plugin to improve compatibility across plugins and themes. The plugin handles integrity and crossorigin for you, among other things. https://github.com/FortAwesome/wordpress-fontawesome – mwilkerson Dec 04 '18 at 17:51