Wordpress script with integrity and crossorigin

前端 未结 7 1275
旧时难觅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:31

    Thanks for all the postings, they really helped. I did roll my own version to give it some structure and make it easier to read and update. Use enqueue as normal, use script for CSS files with a false tag at the end so that it loads at the top. Though it can probably be simplified somewhat.

    add_filter('script_loader_tag', 'add_attributes_to_script', 10, 3); 
    
    function add_attributes_to_script( $tag, $handle, $src ) {
    
            $scripts_to_load = array (
    
                (0) => Array
                  (
                    ('name') => 'popper_min_js',
                    ('type') => '
    
                                     
                  
提交回复
热议问题