Support » Developing with WordPress » wp_enqueue_script ver keeps showing up

  • Resolved vlad_k

    (@vlad_k)


    Hi, when I use wp_enqueue_script to include my own JS it keeps uppending
    ?ver=2.9.2 to the end of the link, I’ve tryed everething, even

    wp_enqueue_script('active_content_check', '/wp-content/themes/runner/engine/video/AC_RunActiveContent.js', false, false, false );

    The resulting source is:

    <script type='text/javascript' src='http://localhost/wordpress/wp-content/themes/runner/engine/video/AC_RunActiveContent.js?ver=2.9.2'></script>

    And obviously my js doen’t get to work, since it doesn’t expect some crasy numbers (WordPress version) on the end of it’s name. I’ve seen many people write about this problem, but not a single solution, accept for add_filter, which did not work. The code I’ve tryed was:

    add_action('init', 'Active_Content_script');
    function Active_Content_script() {
    
    wp_enqueue_script('active_content_check', '/wp-content/themes/runner/engine/video/AC_RunActiveContent.js', false, false, false );
    }
    add_filter('Active_Content_script', 'toscho_script_loader_filter');
    function toscho_script_loader_filter($src)
    {
        if ( FALSE === strpos($src, 'http://ajax.googleapis.com/') )
        {
            return $src;
        }
        $new_src = explode('?', $src); 
    
        return $new_src[0];
    }

    Please help!!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter vlad_k

    (@vlad_k)

    Thanks everyone for helping so hard =))
    Found the solution:
    use
    ‘add_filter(‘script_loader_src’, ‘toscho_script_loader_filter’);’

    When adding the filter, and get reed of

    ‘if ( FALSE === strpos($src, ‘http://ajax.googleapis.com/&#8217;)){
    return $src;
    }’
    Lines, they are not required. This filter gets applied every time when you load a script using wp_enqueue_script, it then brilliantly destroys everething after and including ? sign. You can make it do whatever you like =)) Enjoy

    @vlad__k:

    To remove the version query string, use NULL as the 4th parameter. For example:

    wp_enqueue_script('foo', 'http://example.com/foo.js', false, null);

    Thread Starter vlad_k

    (@vlad_k)

    @demetris:
    Nope, that doesn’t work, ?ver=something is there if null or NULL used. Please check your solutions before posting. As to the date the only thing that worked is a filter with 'script_loader_src' hook that gets trigered every time a custom script is loaded.

    The NULL option for the 4th parameter was introduced in WordPress 3.0.

    It was introduced because people needed to do exactly what you need here, and it works for all functions of the family: wp_(enqueue|register)_(script_style)().

    I see now, by looking at your example, that you must be on 2.9.2. If so, you are right, it does not work. It only works with WordPress 3.0 or newer.

    Thread Starter vlad_k

    (@vlad_k)

    Well then it’s no good to me since I develop for public use- there certainly be other users with older versions of wordpress. I’ll probably do a check if(version>=3.0){ then skip the filter procedure. What was happenning before wordpress 3.0? Did it just append a version on to every custom java script file? Every day I think wordpress cant get any dumber, but it actually bits the odds so far- incredibely hard platform to develop for.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp_enqueue_script ver keeps showing up’ is closed to new replies.