Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is diffrence between wp_enqueue_script() and wp_register_script()

Tags:

php

wordpress

I am not clear when/where I will use wp_enqueue_script() or wp_register_script()

like image 697
azmul hossain Avatar asked Sep 23 '16 06:09

azmul hossain


1 Answers

In simple words;

wp_enqueue_script means, Add in a queue to register the file
wp_register_script means, Register the file immediately

wp_register_script registers a script to be enqueued later using the wp_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.

like image 136
Vikrant Avatar answered Sep 26 '22 08:09

Vikrant