Lets do a quick check of your WordPress source code. Right click on your WordPress article page and click view source. If you carefully see HTML source code, you will notice that few javascripts and style sheets are taking query string arguments. These query strings mostly denote the version of your WordPress or plugin that you are using. Here’s an example of one such javascript and stylesheet.
http://websitename.com/somejavascript.js?ver=3.4.2
http://websitename.com/somestyle.css?ver=3.4.2
These query string does not do any good; Firstly, the hackers can make use of this version information and secondly, it affects your SEO. Let me explain the later part a bit more; URLs that has query strings are not cached by some proxy caching servers including CDNs. Removing query strings from these resources will allow proxy caching and it can boost your website’s performance.
OK! If you are using WordPress, then follow this quick tip to remove query strings from resource URLs.
How to remove query strings from WordPress resource URLs?
Open functions.php file located in your theme directory and paste the below 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 );
That’s it! Reload your WordPress page.
Note: Removing the query strings from your resource URLs will not affect their functionality.
Now Read: How to remove unnecessary meta tags and data from WordPress pages?
I am using astra theme. Will this code still work today? In 16dec 2021.
You can also use simply plugin…. no settings, fast install.
https://wordpress.org/plugins/remove-query-strings-littlebizzy/
don’t need fix your theme each time