How to remove query string from static resource in wordpress

How to remove query string from static resource in wordpress

Posted on 25 Jul, 2015 by Ajani Ashish | No comment

How to remove query string from static resource in wordpress

Before getting a look on how to remove query string from static resources, lets see what is query string.

What is query string?

It is a part of a URL(Uniform Resource Locator) containing some data that does not fit conveniently into a hierarchical path structure. The query string commonly includes fields added to a base URI by a Web browser or other client application after domain name.

It is added to static resources like JS or CSS can cause some problems in getting higher rank.

Benefits:

  • Improve cache performance
  • Better rank in Google search results
  • Google PageSpeed improvements
  • Higher speed in YSlow test results
  • Higher speed in Pingdom and GTmetrix as well.

Here is the simple code which can help, just place the code in functions.php in your theme.

//Add this code in theme functions.php file

function remove_cssjs_ver($src) {
    if (strpos($src, '?ver='))
        $src = remove_query_arg('ver', $src);
    return $src;
}

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

Resources:
https://codex.wordpress.org/Function_Reference/get_query_var
https://en.wikipedia.org/wiki/Query_string

I am a pro at troubleshooting glitches in any code of WordPress. Please feel free to connect with me in case if you like to ask anything related to WordPress.

 

Related Post

4 Amazing features of Apple’s New iPhone 6s & 6s Plus

Posted on 16 Sep, 2015 by Ajani Ashish | No comment I 3842 views

Wait is over for the most awaited iPhone, this time Apple's event is way before Christmas. iPhone 6s and iPhone 6s+ are claimed to be the best phones ever from Apple. There are many things changed since iPhone 4,...

Read More

CAN-SPAM Act – A Law – Subject to penalties

Posted on 27 Apr, 2015 by Ajani Ashish | No comment I 3173 views

CAN-SPAM Act is a thing which you should know since you are planning for online email marketing. First of all, online marketing strategy without email marketing is not even imaginable. Email marketing is very important...

Read More
No Comments (0)

Speak Your Mind

Your email address will not be published. Required fields are marked *