Removing WordPress Version Number From Static Files

Remove WordPress Version Number From Static Files

Version Number Query String on Static Files

If you’ve been working with WordPress for a while, I’ll bet you’ve noticed the query string attached to each .js and .css file loaded by your site. (For those not familiar with query strings, they are all the jargon appended to your files when enqueued, for example &ver=1.1 or something siliar.)

This happens because whenever WordPress includes a script or a style sheet by using the wp_enqueue_style or wp_enqueue_script function it will include a query string for the version of the file. Both of these functions have a version parameter which allows the developer to append any version number that they want to the query string, if the version number doesn’t exist in the function then WordPress will append the WordPress version to the end of the URLs.

This is a problem as many proxies will not cache the resources if it has a query string in the URL. Which can cause the site to not function or display properly for certain users, or it may require extra HTTP requests to retrieve the latest versions etc. In short, leaving query strings on static resources will slow your site down (not by a whole lot, but it will, and those of us who are speed conscious understand every millisecond counts on the web).

Remove Query Strings Sans Plugins

There are a whole lot of plugins in the repository that claim to remove query strings and all sorts of jargon from your enqueued files. It’s quite simple to remove these query strings without the use of a plugin. All we need to do, is use some core PHP functionality to remove the unwanted ver number from our file.

Check out the three most popular methods below:

Method #1:

Removes WordPress version number inside of WP_Head

Method #2:

Removes WordPress version number from all enqueued/included CSS and JS files

Method #3:

Removes all version numbers from all enqueued/included CSS and JS files – the most thorough, which will remove “ver” parameter from every included/enqueued js and css file.

That’s all. Drop any of the above three functions right into your functions.php file of your theme or child theme, re-load a page and check the inspector and see that any previously attached query strings or version numbers are no longer there. You can also test your site on performance checking sites such as Pingdom Speed Test, GTMetrix, Web Page Test or Google Page Speed Insights.

About the Author

Evan Herman

Evan is a full time WordPress developer at Yikes Inc. where he makes all sorts of cool things with WordPress. When he’s not there you can find him developing awesome plugins, blogging about WordPress or hanging out with his three cats and amazing girlfriend in Philadelphia, PA.