0

Can someone explain the version argument in wp_register_script()? According to the codex it is added to the URL as a query string for cache busting purposes.

It also says if the $ver argument is set to null, no version is added and if false, the currently installed version of WordPress is added.

How do I set the $ver argument to null? I thought I had in the code I'm using below but it's adding the currently installed WordPress version as the version number.

function add_ajax_script() {
    wp_register_script('ajax-implementation', '/wp-content/themes/codilight-child/scripts/ajax-implementation.js', array('jquery'), '', false);
    wp_enqueue_script('ajax-implementation');
}
add_action( 'wp_enqueue_scripts', 'add_ajax_script' );

1 Answer 1

1

You literally specify the version number as null:

function add_ajax_script() {
    wp_register_script( 'ajax-implementation', get_stylesheet_directory() . '/scripts/ajax-implementation.js', array('jquery'), null, false);
    wp_enqueue_script('ajax-implementation');
}

add_action( 'wp_enqueue_scripts', 'add_ajax_script' );

An empty string, '' is not the same thing as null.

2
  • Ok, thanks. I did try null but I had it in quotes. Also, I'm curious to know what is meant by cache busting purposes?
    – jrcollins
    Sep 21, 2016 at 7:29
  • Cool! Yeah, 'null' (in quotes) is simply a string and is different than null (the special value). Cache busting is a technique used to override the browser's cache for a particular file. This is handy for when you want to force the user's browser to update a stylesheet (for example) after you (the developer) have modified it. By changing the version number from what it was before, the browser will automatically load a fresh copy of the file. Sep 21, 2016 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.