instant.page icon indicating copy to clipboard operation
instant.page copied to clipboard

Wordpress plugin issue

Open thewebartisan7 opened this issue 5 years ago • 0 comments

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;
}

thewebartisan7 avatar Jun 20 '20 04:06 thewebartisan7