[WordPress] Remove Version Query Strings From JavaScript JS and CSS Stylesheet Files

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:

Thanks to an idea from this post, there is a very simple function that can be added to remove all query strings from script and css files.

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:

Hope you find this helpful!


  1. That’s a cool. Do you know how to remove it from just a specific js file?

    For instance, I actually want the query stings on locally hosted JS for versioning. BUT, for jquery, I serve google’s hosted version b/c it’s more likely to already be cached in a viewer’s browser–more likely that is without the query string.

  2. Wow. Found another way. The WP docs don’t explain this very well. Change the second value from ‘false’ to ‘null.’ and it removes the version string.

    (“http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js”), false, null);

    • I’m lost. Where is this line found? I don’t see it in the previous code you posted nor in the original code posted by John.

  3. Nice shortcut. Thanks.

  4. Thanks for having this in your blog, was great help for me on my blog, will make sure to remember this one. :)

  5. Thanks… I Have Succesfully Modified Minify CSS For W3 Total Cache

  6. Simple, functional and useful. Thank you! Something like I was looking for about 2 hours. Keep it up :o).

    • I’m glad you found it useful. Thanks for the feedback.

  7. Dude thanks alot for this code, I was looking for a way to remove those version info from my css and js scripts for my optimization to work. :) Your code perfectly works. Cheers

  8. Cheers for that, been looking for this for over an hour now, thank you :).

  9. Nice share, Very helpfull for me. And IT works like a sharm.

  10. I’ve included this in my functions file, but it’s just not working. if you use pingdom to check the site: nintendoconnect.com … there are so many plugin versions that are still being queried. Any thoughts?

  11. hi

    thanks for your awesome post

    but there is a problem ! .. the pictures

    some of my pictures have query string

    but what can i do ?

  12. Its very help full on Remove query strings from static resources of Google Page speed service suggestion.


  13. Thankyou very much. I’ve successfully removed the js and css query strings with your script.

  14. Hi John,

    Thanks for the info but it didn’t work for me…I’m using W3TC and it is pointing to my slides on my home page. It caches whatever slide is loading at the time of the test. I would like to remove the query string? from the jpeg to help my Google Page Speed. Any suggestions would be appreciated.

    • @john awesome tutorial man. U made my life easier.

      @Vishal, Did u fix the problem?

  15. tried to put the code into my functions.php but it breaks!!

    Parse error: syntax error, unexpected T_STRING in /home/deb52593/domains/catterycelizes.nl/public_html/wp-content/themes/atahualpa/functions.php on line 975

    so it won’t work for me

  16. thanks alot for this code… :)

  17. Great code man..thanks

  18. Hey there,

    I have put this code at the bottom of my function.php and nothing happen? What am i doing wrong? I still have like 20 links with the query string.

  19. If u have problem using the code, use this one:

    function hide_wp_version($src) {

    global $wp_version;

    return str_replace(“?ver=$wp_version”, ”, $src);


    add_filter(‘script_loader_src’, ‘hide_wp_version’);

    add_filter(‘style_loader_src’, ‘hide_wp_version’);

    Just add to your “function.php” file… Tested :)

    • Or you can simply use WordPress built-in function

      remove_query_arg( ‘ver’, $url );

  20. I updated the function.php and it worked great. So far nothing seems to be broken :)

    It worked for the theme files linking to CSS and JS, however for external files it didn’t work:





    These files still the same as before. Any suggestions?

  21. This code will break any site that enqueues a script that requires querystring parameters, like the Google Maps API. That’s a lot of potential breakage. It would probably be safer to limit that changes to scripts hosted on the local domain, though there’s no guarantee they won’t require querystring parameters. Maybe best would be to only remove the WordPress-specific “ver” parameter.

    • How do I limit this so it does not affect the googlemaps API?

  22. Hi John. How do you do this on drupal? Thanks.

  23. Wow! This helped me a lot! Thanks! :D

  24. John,

    Thanks for sharing! This worked perfectly in WordPress 3.7 with the Genesis framework.

    I spoke too soon. It actually breaks a few CSS calls for Google fonts. I should be able to tweak it. Thanks for getting me started!


    • Hey Jay,

      Were you able to work this out? I am still looking for a solution.

  25. I added this code to my finction.php file (but I’m not exactly sure I put it in the correct place). Since then there has been a text string showing at the very top of my web page. The text string is the exact code I added to the function.php file. So I assumed that was the problem. I removed the code from the file, published, and reviewed my site.

    But it still exists on my site even after clearing history and cache.

    Seems very strange to me. Any ideas?

  26. I used this on my directory and broke the Google Maps API request for the sensor. It wouldn’t recognize the option for true or false. Work great if not using any API services though :)

  27. Didn’t work. The query tags are still showing if I’m using W3TC. :(

  28. Hi John! If my wordpress theme doesn’t have a specific functions.php folder, can I place this function in any of the php folders? I will be so happy if this works!



  1. Remove the version query strings from [WordPress] JavaScript JS and CSS Stylesheet Files | Clynt.com - […] Remove query strings from static resources […]

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Pin It on Pinterest

Share This