Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Last active December 16, 2015 10:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save glueckpress/5421655 to your computer and use it in GitHub Desktop.
Save glueckpress/5421655 to your computer and use it in GitHub Desktop.
[WordPress] Removes version queries from script/stylesheet calls in WordPress, but keeps query of google font stylesheets.
<?php
/**
* Removes file version queries from script/stylesheet calls.
* http://wordpress.stackexchange.com/a/96325/23011
*
* Enhanced to keep query of google font stylesheets:
* Removes “?ver=3.5.1” from http://domain.tld/wp-content/themes/theme/stlye.css?ver=3.5.1
* Leaves http://fonts.googleapis.com/css?family=MyFont untouched.
*/
add_filter( 'script_loader_src', 'gp130419_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'gp130419_remove_script_version', 15, 1 );
function gp130419_remove_script_version( $src ){
$url = explode( '?', $src );
if( 'http://fonts.googleapis.com/css' == $url[0] ) :
$version = explode( '&ver=', $url[1] );
$url[1] = $version[0];
endif;
return ( 'http://fonts.googleapis.com/css' == $url[0] ) ? $url[0] . '?' . $url[1] : $url[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment