Skip to content

Instantly share code, notes, and snippets.

@jemekite
Last active April 6, 2020 18:43
Show Gist options
  • Save jemekite/28bf43aff8c9830e051c to your computer and use it in GitHub Desktop.
Save jemekite/28bf43aff8c9830e051c to your computer and use it in GitHub Desktop.
Remove query strings from static resources and Defer parsing of JavaScript for wordpress
function _remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' async onload='myinit()";
}
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