instantpage / instant.page

Make your site’s pages instant in 1 minute and improve your conversion rate by 1%
https://instant.page
MIT License
6.01k stars 206 forks source link

Wordpress plugin issue #78

Closed thewebartisan7 closed 1 year ago

thewebartisan7 commented 4 years ago

Hi, I notice that the filter add_attributes_to_script() doesn't work because script tag has not the type attribute anymore in Wordpress, or almost in mine Wordpress with default theme TwentyTwenty and without any plugin. I see that this filter replace type="text/javascript" with type="module".

I solved by using below solution, which also add integrity:

add_filter('script_loader_tag', 'add_attributes_to_script', 10, 3); 
function add_attributes_to_script( $tag, $handle, $src ) {
    if ( 'instantpage' === $handle ) {
        $tag = '<script src="' . esc_url( $src ) . '" type="module" integrity="sha384-by67kQnR+pyfy8yWP4kPO12fHKRLHZPfEsiSXR8u2IKcTdxD805MGUXBzVPnkLHw"></script>';
    } 
    return $tag;
}
dieulot commented 1 year ago

This was fixed in the version 5.6.0 of the plugin. (It was triggered on themes using the HTML5 syntax option.)