• Skip to main content

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Code Snippet / Remove WordPress Script Query Strings

Remove WordPress Script Query Strings

By Victor M. Font Jr.
January 5, 20163 Comments

Remove Script Query Strings from WordPress image, public domain image from pixabay.com

Speed… speed… speed… it's all about speed… or is it? For years, the speed in which your site loads has been one of the many "ranking signals" search engines use to assess where your site will display on their search results page. If your site loads too slowly, it will be demoted in the results.

To get the best performance out of a site, developers rely on a number of testing sites that flag potential issues and offer suggestions on how to improve performance. One very popular site is GTMetrix. When you test your site through GTMetrix, it displays the results of Google PageSpeed and Yahoo YSlow. And when it comes to a WordPress site, in almost every case you will see the following red flag for "Remove query strings from static resources":

Remove Query Strings recommendation image

As you can see from the image, every file that displays a query string is either a CSS or JavaScript file. This is because the default behavior for the WordPress wp_enqueue_script function is to append a string specifying the script version number. If the developer added a version number, it is concatenated to the end of the path as a query string. If no version is specified or set to false, then WordPress automatically adds a version number equal to the current version of WordPress you are running. The default setting is false. If the version variable number is set to null, no version number is added, but this requires a purposeful action on behalf of the developer.

If you add the following code to your theme's functions.php file, you will remove the query string version numbers from all of your scripts at once, which in turn results in an improved score in Google PageSpeed.

Alternate Code

As an alternative, this code snippet works just as well as the above.

If everything works as expected, the next time you test your site with Google PageSpeed, you should receive results as follows:

Great Google PageSpeed reults with query strings removed

If testing still shows static resources with query strings, this means that the developers may have bypassed wp_enqueue_script in favor of directly calling the CSS or JavaScript file.

  • 13shares
  • Facebook0
  • Twitter0
  • Pinterest0
  • LinkedIn12
  • Print
  • SMS1

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. Chan

    October 10, 2017 at 6:27 pm

    Guys there are some new query strings like without the key. Example ?123 you see no variable.

    The plugin can remove all it, and no database, so its very fast load

    https://wordpress.org/plugins/remove-query-strings-littlebizzy/

    Hope you like it, cheers Victor

    Reply
  2. Chris Ecklund

    July 12, 2016 at 5:07 pm

    Hi Victor, I tried your code for ” Removing Query Strings”

    The top one did not work but the bottom one did!?

    Weird thing also is that it seems that different themes with studiopress return different results, I guess they are all coded a bit differently!?

    Reply
    • Victor M. Font Jr.

      July 12, 2016 at 11:02 pm

      There are a couple of sites I support that use WP All Import. When that plugin and these techniques are use, it breaks Event Espresso. Both plugin developer teams blame each other. I could either deactivate one or the other plugin and the problem goes away, but leaving the Query strings on the files, fixes the issue.

      Reply

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2023 Victor M. Font Jr.

Return to top of page