How to Remove Query Strings from Static Resources [WordPress]

You Are Here

This tutorial will help you to Remove Query Strings from Static Resources like from JavaScript JS and CSS Style-sheet files. If you want to increase the performance of  your WordPress website, then tools like Google Page Speed and Yahoo YSlow may suggest you to remove the query string from JavaScript and CSS files.

1x1.trans

For Example : I have checked my site speed with GtMetrix website tool, where GTmetrix can help you develop a faster, more efficient, and all-around improved website experience for your users.

You have to just put the URL of your website in the Text box and they will give you best suggestion to improve you WordPress site speed by doing some tweaks. One of this suggestion I got for my website is to Remove Query Strings from Static Resources, which means that most scripts and style sheets 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 now, you can see your JS and CSS files is looking like this :

/wp-includes/js/jquery/jquery.js?ver=1.4.2

Here is the simple solution to Remove query strings from static resources :

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 _remove_script_version( $src ){
	$parts = explode( '?', $src );
	return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

That’s it, after doing this, just check your WordPress websites performance with the GtMetrix and I hope this will really help to Remove Query Strings from Static Resources and Increase you site speed.

Previous:
Next:

Get Free Updates in Your Inbox!


Share This Post On Social Network

DesiTorrents Registrations are Open!
How to Delete your Gmail Account
Security Tips for Blogging
ProBlog WordPress Theme By Magazine3 : Complete Review

Vishal Gaikar

Article by Vishal

I am Vishal Gaikar, Software Engineer, Web Addicted, Living in Maharashtra, India. If you like This post, you can follow Tricks Machine on Twitter, also you can add me on Google+.

  • vipin

    thanks for this…my site’s score is still low…anyway i guess something is still left..

  • Arturo

    HI!
    How can I fix this issue?
    Defer parsing of JavaScript

    Thanks;

    • http://www.tricksmachine.com VISHAL

      Like CSS, scripts must be downloaded, parsed, and executed before the browser can begin to render a web page. Read more details here

  • Barry

    Worked for me! Thanks a ton!

  • http://loftopia.com tyler

    how do I exclude a particular script?

    like: http://maps.googleapis.com/maps/api/js

    Tyler

    • http://www.softwaresbyvishnu.info/cgi-sys/suspendedpage.cgi Vishnu

      even i want to know how to do it.

    • http://www.quakezilla.com Beny Hirmansyah

      Great article, Vishal. These code truly increase my pingdom tool score after implemented. Tyler, if you want to exclude particular script, you can use additional code in my article. I’ve tried before to exclude a google font css file.

  • http://www.the.me/ Dan

    Thanks for this, tried it, but the site went blank after installing the script right before the )); tag.

    Have WP Super Cache installed.

    Any clue?

  • Bilgedede

    Special Thanks for this article. this is working code on my site.

  • http://www.litefeel.com lite3

    Hi. Now the plugin ‘WP Resources URL Optimization’ can do this.
    http://www.litefeel.com/wp-resources-url-optimization/
    it remove query strings and change to dir.

    • http://loftopia.com Tyler

      Hi Lite3; very cool; does it have the ability to ignore certain scripts?

  • http://techiehandy.com handi priyono

    this method works for me, But the plugin css still using query string in there..
    so how to remove that dude.??

  • kenyafever

    My functions.php doesn’t have a closing php tag! Is that possible?

© 2008-2013 - The content is copyrighted to and may not be reproduced on other websites.Designed by Vishal