Created
January 12, 2015 03:02
-
-
Save codearachnid/c58ce37f61cd57c090f9 to your computer and use it in GitHub Desktop.
WordPress automatically adds query strings to enqueued static resources like stylesheets and scripts. This shall remove them on production sites.
This file contains hidden or 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 | |
| /** | |
| * WordPress automatically adds query strings to enqueued static resources like stylesheets and scripts. | |
| * This is meant for caching reasons (e.g. if a script version changes, | |
| * it should prevent the client to use a cached copy of the old one). | |
| * However, this feature can be omitted to improve site performance. | |
| */ | |
| function remove_query_strings_questionmark( $src ){ | |
| $rqs = explode( '?ver', $src ); | |
| return $rqs[0]; | |
| } | |
| function remove_query_strings_ampersand( $src ){ | |
| $rqs = explode( '&ver', $src ); | |
| return $rqs[0]; | |
| } | |
| // hook filters | |
| add_filter( 'script_loader_src', 'remove_query_strings_questionmark', 15, 1 ); | |
| add_filter( 'style_loader_src', 'remove_query_strings_questionmark', 15, 1 ); | |
| add_filter( 'script_loader_src', 'remove_query_strings_ampersand', 15, 1 ); | |
| add_filter( 'style_loader_src', 'remove_query_strings_ampersand', 15, 1 ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keep in mind it will fail Google font libraries and possibly other api loaders