Last active
December 16, 2015 10:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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