I am not sure what to do here. The codex doesn’t have a bunch of information. When loading scripts into your WordPress theme, do you have to register the script first or can you just enqueue it? Both seem to do the same thing.
Registering it just registers the map of $handle to $src. Registering a script will not automatically load it on your site.
Enqueue actually queues the script to be loaded into the markup.
Enqueue will automatically do the registering, so generally you don’t need to use wp_register_script at all.
For registered scripts, you can enqueue them simply by calling wp_enqueue_script on the $handle, without passing the other arguments.
Hope that clears it up
In other words,
//register and enqueue myscript in one step wp_enqueue_script( 'myscript', 'path/to/myscript.js', array( 'jquery' ), '1.2', true );
is equivalent to
//register myscript (tell WordPress it exists and where to find it) wp_register_script( 'myscript', 'path/to/myscript.js', array( 'jquery' ), '1.2', true ); //enqueue myscript (actually add it to the page) wp_enqueue_script( 'myscript' );
it does, although still a little confusing. I just don’t see any reason to have wp_register_script if enqueue does the same thing.
There are some situations where this could come in handy – for example if your theme or plugin has used a script for quite a while and other plugins depends on this script > Compatibility.
But in most cases wp_enqueue_script() is enough
Here’s an article about it: http://wpcandy.com/teaches/how-to-load-scripts-in-wordpress-themes
Using wp_register_script() and wp_enqueue_script() together also makes things more organized and easier to keep track of. I personally, just use wp_enqueue_script()
some good information. Thanks guys
- Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
- Open a support ticket if you would like specific help with your account, deposits or purchases.
- Item Support by authors is optional and may vary. Please see the Support tab on each item page.
Most of all, enjoy your time here. Thank you for being a valued Envato community member.