How to Remove Query Strings From Static Resources

by | Jan 22, 2018 | Dark Side, WordPress

Requirements:

A Child theme with a functions.php file.

If you don’t have a Child Theme yet check out this guide.

1. Query String?

Is just a small piece of letters and numbers added to the end of some files URL, and indicates the version of the file.

This how a Query String looks like:

https://www.mydomain.com/mystyles.css?ver=1.6.

Some servers can’t cache query strings so we can get rid of them to solve the issue you see in tools like GTMetrix and Pingdom called “Remove query strings from static resources”. By solving this your site will get a bit of better score.

Removing Query Strings in WordPress

2. Remove Query Strings

Go to the functions.php file of your Child Theme and paste the next snippet:

1
2
3
4
5
6
7
// Remove query strings
function remove_query_string( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', 'remove_query_string', 15, 1 );
add_filter( 'style_loader_src', 'remove_query_string', 15, 1 );

You just got rid of them πŸ™‚

4 Comments

  1. Simon

    AWESOME!!

    Reply
  2. Sandy Rowley

    The brains are strong in this one, it is. πŸ™‚

    You, my friend are awesome.

    Reply
    • Nico Master

      Thank You so much Sandy πŸ™‚

      Reply

Submit a Comment

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

How to Cache and Boost WordPress Performance

Want to boost your site performance? Learn how to do it by activating caching in your site. With a simply and clean plugin and as always in a couple of minutes. Let’s not forget about the small extra for fixing Google Analytics!.

How to Make any Element Fixed – Divi Builder

Want to learn how to make any Section / Row / Module fixed? So whenever you scroll the element stays in there with you! Learn how to achieve this trick in a couple of minutes with R2D2 help!.

How to Maintain a WordPress Site Clean

Hello everyone, is time to talk about how can you clean your WordPress site for a better maintenance, optimization and security purposes in just a couple of minutes once again!

Follow MasterDivi on Facebook

Be updated with the latest tricks!