XHanch Studio Log in | Register | Cart

Forum

[How to] Remove/mod...
 
Notifications
Clear all

[How to] Remove/modify query string from CSS and JavaScript URL generated by WordPress

1 Posts
1 Users
0 Reactions
1,589 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

In efforts to increase the performance of a WordPress website, tools like Google Page Speed and Yahoo YSlow may direct you to remove the query string from JavaScript and CSS files. Most scripts and stylesheets called by WordPress include a query string identifying the version. This can cause issues with caching and such, which will result in less than optimal load times.

For instance, jQuery.js may show up like:

/wp-includes/js/jquery/something.js?ver=1.6.2

To remove or to change that version query string, in your theme's function file (Appearance > Editor > Functions.php), add the following code before the closing PHP tag (?>) at the bottom of the file:

function css_js_url_clean($src){
    $parts = explode( '?', $src );
    // To remove the query string
    return $parts[0];
    // Or, you may use this one to use your own version
    // return $parts[0].'?ver=[your-own-version]';
}
add_filter('script_loader_src', 'css_js_url_clean', 15, 1);
add_filter('style_loader_src', 'css_js_url_clean', 15, 1);
 
Posted : 07/02/2012 1:56 am
Share:

× Close Menu