Support » Fixing WordPress » php code for removing query string

  • I need a php code that actually work for removing query string. I have read articles and applied a couple methods but they didnt work. Can someone help me?

Viewing 15 replies - 16 through 30 (of 31 total)
  • thanks vjpo

    I dont know if the code is working because my pingdom query score didnt rise

    Did you ever verify that the function is being called? If it is not called, it doesn’t matter what the code is.

    exit(“Function returns $parts[0]”);

    If so I did put that code in and nothing happen once again
    here’s is what I put in

    function hide_wp_version($src) {
    global $wp_version;
    exit(“Function returns $parts[0]”);
    return str_replace(“?ver=$wp_version”, ”, $src);
    add_filter(‘script_loader_src’, ‘hide_wp_version’);
    add_filter(‘style_loader_src’, ‘hide_wp_version’);

    The code is works for scripts and styles those added by wp_enqueue_script and wp_enqueue_style functions with not specified $ver – script version number.

    Well I need it to remove ?ver etc off my querystring, How do i do that with the code? as vtxzy was saying how to get the call function to the code above?

    Okay. I am not a regex specialist but it stripes for me all ?ver=x.x.x of enqueued scripts and styles.

    function hide_version($src) {
        return preg_replace('/\?ver=[.0-9]*/', '', $src);
    add_filter('script_loader_src', 'hide_version');
    add_filter('style_loader_src', 'hide_version');

    Hey thanks for the response, so i put this code at the bottom of my function.php?

    Yep, functions.php

    Ok i put the code in the funcion php and it didnt remove the querystring, at least in my yslow or gt metrix

    Is there any codes i should have in my htaccess file or i need to remove in order for the code to work correctly?

    Try this instead. Goes in your theme’s (child theme’s) functions.php

    // Remove WP version number from js and css files.
    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 );

    does it matter where i put it? i put it at the bottom and I dont think it did anything.

    For me all 3 snippets work. The very first, that charlietech posted in this topic. 2 – mine, and 3 – MickeyRoush‘s.

    charlietech, did you clear the cache to see the changes? Do you use caching plugins or, may be something else ?

    And again, all 3 snippets work only with scripts, those added by wp_enqueue_script and wp_enqueue_style functions.

    Hey vjpo,

    I did cache the page and Im using w3tc. far as ” all 3 snippets work only with scripts, those added by wp_enqueue_script and wp_enqueue_style functions” what did you mean by that? Do i need to put the code somewhere beside the bottom of the page?

Viewing 15 replies - 16 through 30 (of 31 total)
  • The topic ‘php code for removing query string’ is closed to new replies.