Skip to content

Instantly share code, notes, and snippets.

@msaari
Created March 6, 2017 08:44
Show Gist options
  • Save msaari/9368e202ac0d292bd827741e2952d435 to your computer and use it in GitHub Desktop.
Save msaari/9368e202ac0d292bd827741e2952d435 to your computer and use it in GitHub Desktop.
Defer loading JS in WordPress
<?php
if (!(is_admin() )) {
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
// return "$url' defer ";
return "$url' defer onload='";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}
?>
@msaari
Copy link
Author

msaari commented Mar 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment