In simplest terms, registering it only tells WordPress about it, enqueuing it adds it to the website.
If you register it you would still need to enqueue it ( by just supplying the name you registered it with, without supplying the URL ).
You can just go ahead and use the wp_enqueue_script()
Thread Starter
cag8f
(@cag8f)
OK thanks for that. Am I correct then, that in order to be able to include a script on a page, it first needs to be enqueued and registered? If that is correct, what is the reason for this? It sounds like a security measure.
I also see that wp_enqueue_script() will take care of registering the script if the $src parameter is provided.
Thanks.
Not enqueued AND registered (by two different function calls), since enqueuing serves to register if $src is supplied. Then why have register at all? In cases where you need to reference the script by tag even though you do not wish to always enqueue it. Mainly so you can reference it in dependency arguments. This serves to enqueue it without explicitly calling wp_enqueue_script() for that particular script.
When you enqueue, it is always loaded by the page. This is not always desirable for every request. By registering, it is available to be enqueued, but is not actually enqueued unless it is needed through some other mechanism like dependencies. It’s just a different way to organize scripts. You don’t need it if you don’t want to, enqueuing will always work.
Thread Starter
cag8f
(@cag8f)
Then why have register at all? In cases where you need to reference the script by tag even though you do not wish to always enqueue it. Mainly so you can reference it in dependency arguments.
OK this is illuminating–thanks for that.