• theBrettman

    (@thebrettman)


    Coincidentally, I’m using WordPress 3.1.1. Other scripts in the plugin I edited are using the same syntax and no version and they print to the page fine but the ones I added add a version! I just don’t get it! Why does it do this only to the scripts I’m trying to add? Here is one of the lines I’m trying to add:
    wp_enqueue_script('jcarousel', WP_PLUGIN_URL."/wpec_product_slider/js/jquery.jcarousel.js", array('jquery'),'',true);
    I typed it right, didn’t I? Anyone know what is going on here?

Viewing 11 replies - 1 through 11 (of 11 total)
  • See the $ver parameter for more details here:

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Parameters

    Basically it is to do with caching and making sure the right version is always sent to the browser regardless of the current cached version. I believe if you don’t specifically add a version, WordPress add something like what you had (depending on the WordPress version you have installed).

    It won’t affect the running of your site at all and is a really useful feature as it allows developers to specify new versions of their scripts (in themes and Plugins) and make sure that these new versions will be used (rather than the current cached versions).

    Thread Starter theBrettman

    (@thebrettman)

    all the other scripts are putting ver 3.1.1 now too. I think I messed something up but I have no clue what?

    If you are using exactly the same parameter values to enqueue the script I am not sure why there’s isn’t adding some sort of a version number.

    But the point is you shouldn’t really worry about it, the way yours is outputted is the standard way WordPress deals with enqueued scripts. There is no need to try and ‘prettify’ them, your site won’t run any differently.

    Thread Starter theBrettman

    (@thebrettman)

    the problem is it’s giving me error 404 not found on my scripts because of it…

    I’m sure it won’t be the automatic adding of the version number causing it. It will be for some other reason. Is any Plugin modifying anything that could be causing this? Or is the exact path to the script correct?

    Usually it is because the path is incorrect or a dependent script is not being loaded first.

    Have you a link to your site?

    Thread Starter theBrettman

    (@thebrettman)

    Yep it’s your path. Nothing to do with the added on version etc.

    If you try and view the script direct for these two (i.e. NO version number added on):

    http://mushroomgear.com/wp-content/plugins/wpec_product_slider/js/jquery.jcarousel.js

    http://mushroomgear.com/wp-content/plugins/wpec_product_slider/js/jquery.jcarousel.js

    The script cannot be found. So it is a path problem. Make sure the scripts exist and have the correct path, then they will show up fine.

    Thread Starter theBrettman

    (@thebrettman)

    I still wonder why it’s adding the ver 3.1.1 on the end because I know it’s not supposed to do that…

    It IS supposed to do that. It is the way the enqueue system works in WP. If you don’t supply a specific version, or set/leave it at the default value of ‘false’ then the current version number of WP will be added.

    If you really want to get rid of the version number then you can try setting the version to null. This might prevent adding anything to the end of the script name. I haven’t tested it but according to the core code setting it to null will disable it.

    See (line 44) for more the code:

    http://core.trac.wordpress.org/browser/tags/3.1.1/wp-includes/functions.wp-scripts.php

    The parameters for this function are the same as for wp_enqueue_script().

    Thread Starter theBrettman

    (@thebrettman)

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Parameters
    says that the default value for the $ver parameter is false. doesn’t that mean it shouldn’t be adding a version by default if u set it to an empty string?

    Setting it to false, or leaving it blank (which will make it false by default) will cause the current version number of WP will be added as I said above.

    If you want NOTHING to be added then you may want to try setting $ver to null, as per the core trac comment link I posted.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘wp_enqueue_script adding ?ver=3.1.1 to the end of scripts!’ is closed to new replies.