Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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