Created
January 16, 2017 14:45
-
-
Save mohammad-ahid/507535259827c2cb608434bd4e6a81b1 to your computer and use it in GitHub Desktop.
Remove query strings from enqueued resources in WordPress
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 | |
/** | |
* 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment