• Skip to main content
  • Skip to primary sidebar

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

  • 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

Remove WordPress Script Query Strings

January 5, 2016 By Victor M. Font Jr.

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

Filed Under: Code Snippet, Computers and Internet, Programming, SEO, WordPress Tagged With: Code Snippet, Computers and Internet, Programming, SEO, WordPress

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.

Primary Sidebar

Shopping Cart

Books

  • Winning With WordPress Basics 2nd Edition Winning With WordPress Basics 2nd Edition $19.95
  • Ultimate Guide to the SDLC front cover The Ultimate Guide to the SDLC
    Rated 5.00 out of 5
    $74.95

Recent Articles

  • Modern Scam Defense: How Consumers and Businesses Can Recognize and Stop Email, Phone, and Text Fraud
  • How to Write a PRD So Dense It’s Technically a Novel
  • Top 5 Plugin Names That Scare Our Legal Department
  • When Agile Meets Our 3-Year Waterfall Roadmap: A Love Story
  • Why Our Enterprise Needs 27 Stakeholders to Approve a Button Color Change

Top 10 Article Categories

Best Practice Code Snippet Computers and Internet Genesis How To Leadership Programming Servant Leadership Tutorial WordPress

 
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.