• So I’ve researched how to remove query strings to speed up my site by editing the .PHP file and it seems every recommendation gives different code to use to supposedly fix the same problem.

    Why is this?

    Which code should I use out of the two that I found?

    1.

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

    2.

    //* TN – Remove Query String from Static Resources
    function remove_css_js_ver( $src ) {
    if( strpos( $src, ‘?ver=’ ) )
    $src = remove_query_arg( ‘ver’, $src );
    return $src;
    }
    add_filter( ‘style_loader_src’, ‘remove_css_js_ver’, 10, 2 );
    add_filter( ‘script_loader_src’, ‘remove_css_js_ver’, 10, 2 );

Viewing 3 replies - 1 through 3 (of 3 total)
  • The second is more bulletproof, but both are bad advice. The comment says “static resources” but it will affect dynamic resources also.
    There is much more javascript in WordPress than there used to be, so nowadays it’s not a very good idea to remove the version. Also, your visitors could get mixed versions from your theme if the version is removed (and an update happens).
    If you use a plugin for security, those often have an option to remove the ones that makes sense to remove, instead of a blanket removal like your example does.

    Thread Starter mrrobtfp

    (@mrrobtfp)

    Oh, thanks for the reply Joy. I see your point there.

    Unfortunately my security plugin (Wordfence – Free) does not appear to have the option to remove query strings…

    Do you think there is an alternative code that would still remove query strings without affecting the dynamic resources as well I could use or should I just leave things the way they are and focus on speeding my site up through other avenues?

    I would leave it alone. I don’t see how removing it could speed things up.
    A cache plugin could improve speed a little.
    If you run your site through Google Page Speed, you’ll get specifics to improve. Otherwise, you’re shooting in the dark.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to know which code to use? (Removing Query Strings)’ is closed to new replies.