I’m back with another tutorial that aims to help you not only resolve a longstanding WordPress challenge but it will also increase the overall website performance.

Today’s tutorial comes from a recent customer inquiry I fielded not long ago. The customer’s WordPress website has been integrated to use CloudFlare — if you’re not using this service, then you need to start ASAP.

I’ve integrated a number of WordPress websites to use CloudFlare, and all have witnessed the increased performance, which has led to a bump in organic search traffic.

Although this particular customer’s website had been integrated with CloudFlare, there remained a number of challenges — browser caching, 30+ external CSS and JS files, and good ole’ WordPress version query parameters appended to static resources.

When optimizing a WordPress website integrated with CloudFlare, ensure that the necessary CloudFlare features are enabled and set properly — caching, image compression, etc.

Prior to purging CloudFlare and WordPress caching options, I performed an optimization test on the customer’s website using Pingdom Tools.

As I anticipated, the website’s Pingdom performance grade was an atrocious 55 out of 100, then 72 out of 100 due to the following issues:

  • 35+ external Javascript Files due to a variety of WordPress plugins
  • Downloads across hostnames were not parallelize
  • 15+ external CSS files not minified
  • No browser caching enabled
  • Too many query strings appended to static resources

As mentioned before, I performed the first action item, enabling and properly setting caching, image compression, and minifying CSS/JS file settings in both CloudFlare and WordPress.

I then resubmitted the site to Pingdom only to discover the pesky error about removing query strings from static resources.

WordPress natively appends version query parameters to static resources — crippling the user and search experience to that of sub-optimal load and response times.

The good news though is that there is an easy way to fix and remove version query parameters being appended to static resources in WordPress.

The first option consists of adding a little code logic to the functions.php, while the second option offers the ability to use the following two plugins:

I won’t cover both plugins due to intuitive documentation on using both for optimal performance.

However, there may come a time when plugins clash — just like in this customer’s case, and you’re left without a viable solution, so you think.

And I know many of you have a fear of touching WordPress PHP code. The good news is that if you can copy and paste the following lines of code, then you’ll boost website performance having removed query strings from static resources.

Within your website’s WordPress theme, find the function.php file, and copy and paste the following lines of code:

<?PHP

/* Remove Query String from Static Resources */
function remove_wp_ver( $src ) {
if( strpos( $src, '?ver=' ) )
	$src = remove_query_arg( 'ver', $src );
	return $src;
}

add_filter( 'style_loader_src', 'remove_wp_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_wp_ver', 10, 2 ); 


?>

That’s it! This is all there is to removing query strings from static files. Just that easy!

And for those who don’t feel comfortable editing the functions.php file, you can also use the Code Snippets plugin.

Once code has been added, you can now test your website using Pingdom Tools and hopefully discover the “Too many query strings appended to static resources” error message has been eliminated.

When I made the aforementioned changes and performed the Pingdom Tools test on the previous customer’s website, the overall performance of the website increased drastically from 55 to 72 to 81 — still room for greater improvement.

That simple addition of code to remove and fix query strings appended to static resources is worth the time and effort to implement — especially knowing overall website response and load time is exponentially reduced.

Not only will your website visitors and regulars thank you for an optimized website experience, but search engines are likely to give you a boost in rankings too.

Let me know if you have questions or run into any issues in your attempt to remove query strings from static WordPress resources.

That’s all for now!

Share:
Written by Alvin Brown
He's an experienced and passionate serial entrepreneur, founder and publisher of Kickstart Commerce. Alvin possesses a great love for startups dominating their market using profitable digital strategies for greater commerce.