Skip to content

Instantly share code, notes, and snippets.

@jmsmrgn
Created February 1, 2016 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmsmrgn/ee194c55afaaaec69dd9 to your computer and use it in GitHub Desktop.
Save jmsmrgn/ee194c55afaaaec69dd9 to your computer and use it in GitHub Desktop.
WP - Async script load
// Async load
function async_scripts($url) {
if (strpos( $url, '#asyncload') === false) {
return $url;
} else if (is_admin()) {
return str_replace('#asyncload', '', $url );
} else {
return str_replace('#asyncload', '', $url )."' async='async";
}
}
add_filter('clean_url', 'async_scripts', 11, 1);
// '.js#asyncload' will add async='async' to tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment