• Resolved patrickhealy

    (@patrickhealy)


    I’ve been trying to figure out a way to remove query strings from static resources as per the recommendation in GTmetrix. The only answer I can come across is to untick the setting in W3 for “Prevent caching of objects after settings change”. I did that and I’m still getting this alert. Anyone have any ideas?

    BTW, I am using Cloudflare if that helps and everything else seems to be working as it’s supposed to.

    https://wordpress.org/plugins/w3-total-cache/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter patrickhealy

    (@patrickhealy)

    I also tried using a plugin that was recommended (which I would rather not do) and it didn’t work either. Anyone have a snippet that will do this in the current version of wordpress?

    /* Remove Query String from Static Resources */
    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 );
    Thread Starter patrickhealy

    (@patrickhealy)

    Good looking out. This goes right into the functions.php file right? Does it matter where?

    Goes into the child theme’s functions.php file anywhere after the opening <?php tag, below the last function (if you have other) it’s OK.

    This doesn’t seem to work. All the query strings are still on my js and css files.

    @jeremyers1 – if you aren’t the O.P. with another profile – and unless you are using the same version of WordPress on the same physical server hosted by the same hosts with the same plugins, theme, and configurations as the original poster, do not post in someone else’s thread. Start your own topic.

    https://codex.wordpress.org/Forum_Welcome#Where_To_Post

    Thread Starter patrickhealy

    (@patrickhealy)

    Sorry I never replied to this string. This worked great. Thanks @tizz. You are a star. This stuff can be so daunting.

    You’re welcome. Please, mark this as resolved.

    I used the code and it worked but, it did something to my fonts, everything written looks different even the colors of it, padding is wierd too,

    anyone experienced this?

    Thank you

    • This reply was modified 8 years, 3 months ago by ma001.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove query strings from static resources’ is closed to new replies.