I am not clear when/where I will use wp_enqueue_script()
or wp_register_script()
In simple words;
wp_enqueue_script
means, Add in a queue to register the filewp_register_script
means, Register the file immediately
wp_register_script
registers a script to be enqueued later using thewp_enqueue_script()
function.
wp_enqueue_script()
registers the script if $src provided (does NOT overwrite), and enqueues it. source: Developer.wordpress
Here is brief Answer on WordpressDevelopment
wp_register_script( $handle, $src, $deps, $ver, $in_footer );
Scripts that have been pre-registered using wp_register_script() do not need to be manually enqueued using wp_enqueue_script() if they are listed as a dependency of another script that is enqueued. WordPress will automatically include the registered script before it includes the enqueued script that lists the registered script’s handle as a dependency.
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
wp_enqueue_script() links a script file to the generated page at the right time according to the script dependencies, if the script has not been already included and if all the dependencies have been registered. You could either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With