Created
March 6, 2017 08:44
-
-
Save msaari/9368e202ac0d292bd827741e2952d435 to your computer and use it in GitHub Desktop.
Defer loading JS in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From here: http://www.laplacef.com/2014/05/24/how-to-defer-parsing-javascript-in-wordpress/