Wordpress script with integrity and crossorigin

前端 未结 7 1180
旧时难觅i
旧时难觅i 2021-02-03 12:07

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

相关标签:
7条回答
  • 2021-02-03 12:40

    I just cracked this by accident. I've had to use conditionals on some CSS files for ancient Internet Explorer versions and figured I may as well try putting an array in the same wp_script_add_data function that I used. It works!

        wp_register_script('jquery3', 'https://code.jquery.com/jquery-3.3.1.min.js', array(), '3.3.1', true); // jQuery v3
        wp_enqueue_script('jquery3');
        wp_script_add_data( 'jquery3', array( 'integrity', 'crossorigin' ) , array( 'sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=', 'anonymous' ) );
    

    Reference: https://developer.wordpress.org/reference/functions/wp_script_add_data/#parameters

    For completeness: If adding jQuery v3, you also need Migrate v3: http://jquery.com/download/

    0 讨论(0)
提交回复
热议问题