Novice Remove query strings from static resources

Hello - can somoene please tell me how best to remove the query strings - and where are they to begin with . .- im a novice.
thanks
a

Hey There,

Open up functions.php in your child theme and add following code:

function _remove_script_version( $src ){
$parts = explode( ‘?ver’, $src );
return $parts[0];
}
add_filter( ‘script_loader_src’, ‘_remove_script_version’, 15, 1 );
add_filter( ‘style_loader_src’, ‘_remove_script_version’, 15, 1 );

1 Like

You can also install the plugin called Remove Query Strings From Static Resources if you aren’t comfortable with the code, with you being novice…

as a novice with a small n not a captia N, i was able to follow your orders without installing plugins – which im very happy about :]] Big thanks formidable job. . Great support . . :]

2 Likes

You should really reconsider doing this, @drew111 . It gets a lot of users in trouble in ways they’re not even aware of. WordPress uses those query strings to manage version control of many of the system & themes files, among other things. If you remove them, old versions of files will get cached for visitors after updates and upgrades, which can cause major issues for visitors that you will never see.

If you’re doing this for page speedup purposes, you should be aware - the recommendation is NOT “remove query strings”. It’s “remove query strings and encode them in the URL”. If you don’t do the second step (and it’s quite a bit of dev work to do so) you will create far more problems than you solve.

Also, removing query strings only has a minor effect and only in very specific circumstances. It has no effect on most of the caching used on typical WP sites. It’s just simply not a good idea to remove them.

Hope that helps?

Paul

4 Likes

hi Paul… its a pleasure to meet you and thanks for your time and explanation - what you say makes lots of sence - and in fact- i amended the functions.php to this - and it did not really make a big difference. - so as per your suggestions, im gonna clear the file back to what it was before and

I can see that as per GTMetrix my page score is low - and lots of different issues with lots of stuff i do not understand - so i think im gonna look into the possibility of changing server people - and get a professional who can help - get my site to what it needs to be.

My problem at the momoent is the more i try to fix things - the less time i spend - on what i should be doing which is updating my new products and blogs and stuff.

many thanks your info was a big help :]
regards
andrew

<?php function removescript_version( $src ){ $parts = explode( '?ver', $src ); return $parts[0]; } add_filter( 'script_loader_src', 'removescript_version', 15, 1 ); add_filter( 'style_loader_src', 'removescript_version', 15, 1 ); // ============================================================================= // FUNCTIONS.PHP // ----------------------------------------------------------------------------- // Overwrite or add your own custom functions to X in this file. // =============================================================================
1 Like

I agree with Paul on this one. Removing them isn’t a good idea. Certain plugins can remove them and add the version to the filename, like WP Rocket. This is a great alternative.

If you want to post your URL, I can give you some specific feedback about your site’s score.

1 Like

Drew - just be very careful that you’re addressing the actual speed of the site, not just chasing recommendations from PageSpeed. There are many things that “can” be addressed according to PageSpeed that in real life will have next to no effect, or may not even apply to your site at all.

Always go by the actual speed (and test several of your critical pages, not just your home page) to decide when & where to spend your time. Because as you say - its’ time taken away for other essential tasks when you’re handling it all yourself.

And yes, a quality host is the baseline you need for a fast site.

Good luck!

Paul

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.