WordPress issue with wp_enqueue_script

I am trying to download wp_enqueue_script to load my javascript, here is my code:

<?php wp_enqueue_script('slider','/wp-content/themes/less/js/slider.js',array('jquery'),'1.0'); ?>

It does not work, when I look at the source, it looks like this:

<script type='text/javascript' src='http://localhost/wp/wp-content/themes/less/js/slider.js?ver=2.9.2'></script> 

? ver = 2.9.2 is automatically added to the end, I think this is the reason how I can fix it.

+5
source share
4 answers

To remove the version parameter, you will need an additional filter. This is how I use jQuery for Googles without a query string:

<?php
// Use the latest jQuery version from Google
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', false, false);
wp_enqueue_script('jquery');

add_filter('script_loader_src', '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];
}
?>

You can even use the last filter to add your own custom queries.

Normally, the query string should not affect your script. I delete it only to increase the likelihood that the user can use the cached version of this file.

+5

Wordpress .

false null , ?ver=2.9.2.

+9

You can use null as the fourth parameter if you are using Wordpress 3.0. This will effectively remove the version.

+2
source

Change your code to:

<?php wp_enqueue_script('slider','/wp-content/themes/less/js/slider.js',array('jquery'),null); ?>
+1
source

All Articles