Skip to content

Instantly share code, notes, and snippets.

@landbryo
Last active June 1, 2018 17:46
Show Gist options
  • Select an option

  • Save landbryo/59709cd9d8af3010e0e3f43f0cc025e8 to your computer and use it in GitHub Desktop.

Select an option

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/
//////////////////
// 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