WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_enqueue_script ver keeps showing up (6 posts)

  1. vlad__k
    Member
    Posted 3 years ago #

    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!!!!

  2. vlad__k
    Member
    Posted 3 years ago #

    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/')){
    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

  3. demetris
    Member
    Posted 3 years ago #

    @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);

  4. vlad__k
    Member
    Posted 3 years ago #

    @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.

  5. demetris
    Member
    Posted 3 years ago #

    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.

  6. vlad__k
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic