This topic has 2 replies, 2 voices, and was last updated 7 years, 5 months ago ago by Olga Barlow
Hey….i would like to defer js files and i have tried to use following code in my function.php
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, ‘.js’ ) ) return $url;
if ( strpos( $url, ‘jquery.js’ ) ) return $url;
return “$url’ defer “;
}
add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );
But with this code all xstore shortcodes are broken in their appearance…..
Is there any hint to solve that problem?? Maybe any code to exclude the js files of the theme?
Thanks a lot
Hello,
Try the following code instead of that one
function defer_parsing_of_js ( $url ) {
if ( ( FALSE === strpos( $url, ‘.js’ ) ) || ( strpos( $url, ‘jquery.js’ ) > 0 ) || ( strpos( $url, ‘head.min.js’ ) > 0 ) ) return $url;
return “$url’ defer “;
}
Also, there is special WP plugin for these purposes WP deferred javaScript.
Regards
You must be logged in to reply to this topic.Log in/Sign up