wp_register_script( $handle, $src, $deps, $ver, $in_footer );

If $ver is not required then should we leave that space blank? or completely remove the commas?

Example →

wp_register_script( 'scroll', get_template_directory_uri() . '/js/infinite-scroll.pkgd.min.js', array( 'jquery' ), '1.1', true );

There is no dependency on JQuery. this needs to be removed entirely:

, array( 'jquery' ),

or leave it blank like this →

    wp_register_script( 'scroll', get_template_directory_uri() . '/js/infinite-scroll.pkgd.min.js', , '1.1', true );
  • 1
    Leaving it blank would be invalid PHP – Tom J Nowell Sep 26 '17 at 0:57

Simply pass in null or the empty equivalent.

For example, if you don't depend on anything, say so. It's expecting an array of the dependencies, so pass an empty array array()

Or pass in null


you cant leave it empty, at least you have to put an empty string '', it will default the dependency to array() and the version to false:

wp_register_script( 'scroll', get_template_directory_uri() . '/js/infinite-scroll.pkgd.min.js', '','' , true );

for readability you can, and its used widely:

wp_register_script( 'scroll', get_template_directory_uri() . '/js/infinite-scroll.pkgd.min.js', array(), null , true );

with would be just the same.

  • 1
    You can't leave it blank, it will throw a syntax error Parse error: syntax error, unexpected ',' . – Jacob Peattie Sep 26 '17 at 2:38
  • 1
    true, i answered checking the core code, i updated my answer – David Lee Sep 26 '17 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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