This page on the Codex gives us a list of all the default scripts that ship with WP. But how do we know which ones are actually being used so we don't have to manually enqueue them? Or do we care, and just enqueue the ones we need, and wp_enqueue_script() will just ignore the enqueue request if that script is already loaded?

But what about versions? If I'm going to be specifying versions with wp_enqueue_script and the version that ships with WP is less than that, will the wp_enqueue_script call just be ignored, and I find myself without the script I'm looking for?


I'll answer each of your questions in order:

Do we care which scripts are enqueued?

Not really. WordPress registers each script and maintains it in an array. When you enqueue the script, WordPress will load it and any dependencies it has when it calls wp_print_scripts() (which is tied to the wp_head hook).

If you enqueue a script twice, it's only printed once. So don't worry about it. Just always enqueue what you need.

What about script versions?

WordPress will only let you register one version of a script. So if an older version is already registered, you can't register the new one.

Calling wp_enqueue_script() with the new version won't actually enqueue it, either. When you try to enqueue a script with the full URI, WordPress will first register the script, then enqueue it ... so if an older version is already registered, you'll end up enqueuing it instead.

If you absolutely need to enqueue a new version (i.e. you want to use the latest version of jQuery rather than the one that ships with WordPress), you need to first unregister the old version, then register/enqueue the new version.

Someone else has already covered how to do this in another question, so I'll just refer you there ...


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.