WPVKPWPVKP

  • Our Themes
    • Fastest
  • WordPress
    • Genesis
  • Guides
    • Fix
    • SEO
    • CDN
    • Hosting
  • Contact Us

Easily Remove Query Strings from Static Resources In WordPress Websites

Editorial Team 26 Comments

Want to score well in Google page speed test. Then you have to remove query string from all CSS and javascript files in your WordPress website.

There are many different factors which affect your total page load time and Google page speed test consider all of those factors. According to Gtmetrix, removing query strings from static resources like stylesheet and javascript has the higher priority which is considered during the speed test.

Note: If you don’t like reading and want one simple solution to remove query string then download my plugin, install it and forget it. It will do all complex task in the background and you don’t even need to configure it.

Download

Contents

  • 1 What Is Query String?
  • 2 How To Remove Query String From Static Resources
    • 2.1 #1 Using Custom Code
    • 2.2 #2 Using A Plugin

What Is Query String?

The query string is a method by which different plugins pass the content values or carry the version detail. They are used in both javascript and stylesheets. Actually, it’s one of the methods implemented by developers to instantly render new updates.

Here’s the explanation. Let’s say you are a developer and you have created a plugin which has few CSS and js files. Now if anyone who is using your plugin and also using a CDN service then these static files ( both CSS and js files ) will be cached for weeks, months or for even one year.

Now if you push up any update to your plugin it will not be visible until the cached file expires. So developers use the query string as it is not cached by most of the browsers and CDN services. Overall it might be helpful for web developers and designers but is a bad practice and have a great impact on your website’s loading speed.

How To Remove Query String From Static Resources

remove query string from wordpress

I have two different options for you. You can either chose to edit your theme manually and add the custom code to your function.php file. Or you can go with the plugin which is, as usual, easy to install.

#1 Using Custom Code

I have already developed a plugin do this task, but if you still want to do it manually then follow the steps properly. You have to just place it in your current theme’s function.php file. You can either choose to edit your theme via WordPress dashboard or you can even use FTP or online file manager.

Simply navigate to your WordPress dashboard then to appearance. Then from on hover menu select the editor. Now on the right-hand side search for function.php and place the code at the bottom.

// Remove query string from static files
function remove_cssjs_ver( $src ) {
 if( strpos( $src, '?ver=' ) )
 $src = remove_query_arg( 'ver', $src );
 return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );

With the help of this code ?ver string will be removed. It can be altered as per need. But before making any changes, I will request you to create a backup of theme’s function file.

#2 Using A Plugin

I think it is the easiest way to manage all types of “?” queries. You don’t need to edit any file, not you have to create any backup. Just install remove query strings from static resources plugin and you are done.

If you are still facing any problem then you can contact me directly from the comment section.

Comments

  1. Pat Yo says

    This shit did not work, Didn’t even Dent in my stuff

    Reply
    • Vivek Kumar says

      Problem is that, you don’t know who to use it.

      You can download my wordpress plugin if you don’t have any idea on how to use the code snippet.

      Reply
  2. Rubén Manzano says

    Works fine without plugin, I put it in child theme.

    Thank you very much.

    Reply
  3. Alex says

    Your plugin has broken functionality of my website and now I can’t revert it even if I disable and delete your plugin!!

    Thank you!

    Reply
    • Vivek Kumar says

      I have been using this plugin for more than 2 years. It has also been updated so as to be compatible with latest wordpress updates. It is being used by thousands and none complained me about it.

      Reply
  4. Flofre says

    Hi Vivek
    I tried the plugin, No change
    I tried the code (if I did it right), No change.
    I think I have used 2-3 days to google around and solve it (I’m persistent… 😉 )
    I hope You have an idea.
    This is my Pingdom test: http://tools.pingdom.com/fpt/#!/dLNcDz/https://energig.com/da

    And my functions.php from my Child theme:

    <?php
    //
    // Recommended way to include parent theme styles.
    // (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
    //
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
    get_stylesheet_directory_uri() . '/style.css',
    array('parent-style')
    );
    }
    //
    // Your code goes below
    //

    I tried pasting your code in the bottom as described but… No change 🙁

    I have tried finding other solutions, but I'm not techie enough.

    I really hope that you have inputs 🙂

    //Flofre

    Reply
    • Vivek Kumar says

      You site is having 97 upon 100 grade… actually perfect grade.

      After looking at you site’s source code it seems that parameters have gone.. href=”https://energig.com/wp-content/cache/minify/000000/29fcd/default.include.132782.css
      https://energig.com/wp-content/cache/minify/000000/29fcd/default.include.3177c1.js

      This code snippet is working for you.

      Thanks for commenting.

      Reply
      • Flofre says

        Thanks Vivek
        Yes the 97 upon 100 is not bad. Now I have to find out why it takes 4 seconds to load. Same page was 1 second last week and I don’t think anything big has changed, so I have set some parameter somewhere that makes the page wait almost 3 second in the pingdom waterfall first 2 lines.
        But thats not your problem 🙂
        Thanks 🙂

        Reply
  5. Hansjörg says

    This snippet works just for css and javascript files. And does its job, thanks!
    Now i need a way to do the same for an embedded video file.
    Is there any way to get rid of the query string for a video file in the content section? Preferably without the overhead of filtering the whole content… 🙂

    Reply
  6. saket anand says

    Thanks Mate,it work like a charm 🙂 i have tried it manually instead of plugin.

    Reply
  7. duc4231 says

    nice tool, thanks

    Reply
  8. Mick M says

    Hi,

    I’ve installed the plugin but it won’t work. I dit some new tests on pingdom.com but no better results.

    Can you help me out?

    Greetz Mick

    Reply
    • Vivek Kumar says

      1. You have to install this plugin :: https://wordpress.org/plugins/remove-query-strings/
      If you have already installed it, then deactivate it and then re activate it.

      2. If you are using any cache plugin like wp rocket, wp super cache or w3 total cache, then please clear the cache or purge the cache.

      3. If you are using cloudflare then please purge all your cache.

      Then visit your website and hard refresh your website by ctrl+f5 ( on chrome ) and right click and choose view page source.

      Search the page ( ctrl+f ) for any css file and most probably the ? ( query string ) must have been removed.

      Reply
  9. Ben Nelson says

    Hi Vivek,

    While the above two solutions sped up my homepage speed results, my listings search and specific listings pages still have ‘remove query strings from static resources issues’.

    https://www.dropbox.com/s/xjjp5utz8feq3l1/Screen%20Shot%202017-01-28%20at%2012.08.55%20pm.png?dl=0

    https://www.dropbox.com/s/4eq91brmlb9ny27/Screen%20Shot%202017-01-28%20at%2012.10.46%20pm.png?dl=0

    How do I tackle this issue on other pages?

    Regards,

    Ben

    Reply
  10. Autoankauf says

    Thank you , this plugins are very useful

    Reply
  11. Sandeep says

    Can it remove other Domains query string

    Reply
  12. Howard says

    I’m thinking of trying this plugin. Ironically, pingdom notes 4 query strings (and it’s all from my email application MAILERLITE. ) Do not understand any of it)
    Another STRANGE thing is that on Google Page Speed,,, it’s not even mentioned! (97 desktop 100 mobile!!) what are your thoughts?
    Howard

    Reply
    • Vivek Kumar says

      It seems that its cache problem. I will suggest flushing all your cache, including CDN. And then try the Pingdom test. If you still see any query string warning please share the test url with me.

      Reply
  13. Howard says

    Hi
    I use autoptimize , Cache enabler and async JavaScript
    Still get queery strings on pingdom.queery strings; all seem to involve my email application: Mailerlite
    www.vintageandsound.com
    Thanks
    Howard

    Reply
  14. Samuel O'Rourke says

    Hi Vivek,
    I have tried both methods and still when I do the Pingdom test and GT test get reports that queries still exist. I am no specialist in this area so really appreciate any help you can provide.
    If I have installed the app correctly and put the code in correctly is there a reason that I would still be having these issues

    Reply
    • Vivek Kumar says

      Your problem cannot be solved with this plugin. The problem you are facing is because of wordpress.com CDN service. I am 100% confident that you are using Jetpack’s photon service.

      The query string which you are seeing is actually to help you make your website faster by serving the best optimized image considering the current screen resolution.

      Reply
  15. Howard says

    Hi
    Please check my domaine on pingdom and tell me what ” these queery strings mean? Should I try your plugin ? No other one seems to work
    Thanks Howard
    http://www.vintageandsound.com

    Reply
  16. Howard says

    Hi:
    These are the query string listed on my site.

    http://static.mailerlite.com/data/webforms/366087/x6y7v7.js?v6

    http://static.mailerlite.com/js/w/ml_jQuery.inputmask.bundle.min.js?v3.3.1

    http://static.mailerlite.com/js/w/webforms.min.js?v3772b61f1ec61c541c401d4eadfdd02f

    http://www.vintageandsound.com/wp-content/theme … llyviral/fonts/fontawesome-webfont.woff2?v=4.4.0

    I have not used plugin yet
    Are these 3rd party query strings?
    Would your plugin work?
    Thanks

    Reply
    • Vivek Kumar says

      Sorry to say, but in your case no plugin will work, because they are 3rd party scripts.

      Reply
  17. Lefteris says

    hello, I have added the string manually but looks like it doesn´t Work when I am running the test on pingdom.com.

    Reply
  18. Kristov says

    Hey brother you can try another good one:
    https://wordpress.org/plugins/remove-query-strings-littlebizzy/

    no settings or database so can very fast if you have PHP Opcache installed…
    check their docs

    Reply

Leave a Reply Cancel reply

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

Latest Updates

  • How to Fix The Spinning Wheel on Mac When Opening Websites
  • 5 Ways Social Media Can Enhance Employee Retention
  • How to use Telegram as a customer service channel
  • How To Improve On-Page SEO For Your WordPress Website?

Copyright ©2020 · WPVKP - All Rights Reserved · Read Our TOS & Disclaimer