How to remove query string from WordPress URL and Why you should? – SEO

Updated on September 2, 2017

Lets do a quick check of your WordPress source code. Right click on your WordPress article page and click view source. If you carefully see HTML source code, you will notice that few javascripts and style sheets are taking query string arguments. These query strings mostly denote the version of your WordPress or plugin that you are using. Here’s an example of one such javascript and stylesheet.

These query string does not do any good; Firstly, the hackers can make use of this version information and secondly, it affects your SEO. Let me explain the later part a bit more; URLs that has query strings are not cached by some proxy caching servers including CDNs. Removing query strings from these resources will allow proxy caching and it can boost your website’s performance.

OK! If you are using WordPress, then follow this quick tip to remove query strings from resource URLs.

Wordpress seo
WordPress seo

How to remove query strings from WordPress resource URLs?

Open functions.php file located in your theme directory and paste the below code.

function _remove_script_version( $src ){
    $parts = explode( '?ver', $src );
        return $parts[0];
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

That’s it! Reload your WordPress page.

Note: Removing the query strings from your resource URLs will not affect their functionality.

Now Read: How to remove unnecessary meta tags and data from WordPress pages?

Was this article helpful?

Related Articles

Comments Leave a Comment

  1. I am using astra theme. Will this code still work today? In 16dec 2021.

Leave a Comment