Last active
June 1, 2018 17:46
-
-
Save landbryo/59709cd9d8af3010e0e3f43f0cc025e8 to your computer and use it in GitHub Desktop.
WordPress function to defer jQuery parsing using the HTML5 defer property. Helpful resource: https://developer.wordpress.org/reference/hooks/clean_url/
This file contains hidden or 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
| ////////////////// | |
| // DEFER JQUERY // | |
| ////////////////// | |
| if (!(is_admin())) { | |
| function defer_parsing($url) { | |
| if (FALSE === strpos($url, '.js')) return $url; | |
| if (strpos($url, 'jquery.js')) return $url; | |
| return "$url' defer onload='"; | |
| } | |
| add_filter( 'clean_url', 'defer_parsing', 11, 1 ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment