Title: wp_register wp_enqueue
Last modified: May 21, 2023

---

# wp_register wp_enqueue

 *  Resolved [Mauro Vicariotto](https://wordpress.org/support/users/mrosfy/)
 * (@mrosfy)
 * [3 years ago](https://wordpress.org/support/topic/wp_register-wp_enqueue/)
 * Hi all,
 * once again I wish to go back to the functions “`wp_enqueue_script`” and “`wp_register_script`”(
   or style).
 * In several publications I read that recently is no longer needed to register 
   a new code, and that the “enqueue” method is enough for the whole job:
 * actually from [https://developer.wordpress.org/reference/functions/wp_enqueue_script/](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)
   it seems that it is correct to add parameters (handle, src, array, etc.) directly
   to “`wp_enqueue_ ..`” function.
 * But in other publications (f.e. [https://gloriathemes.com/wordpress-enqueue-scripts-and-styles/](https://gloriathemes.com/wordpress-enqueue-scripts-and-styles/))
   it is stated that “to use the hook “`wp_enqueue_scripts`” it is correct to use“
   enqueue” method only after “registered” the code: it could be that they are old
   publications (in fact I dislike when a publisher doesn’t put a date) but on the
   web there is too much controversial information on this issue.
 * In child theme functions.php I tested both ways, and both work fine for me, but
   still not clear which one is the appropriate method today.
 * For temporary the solutions which I have decided are as follows:
    1. To override previous parent theme scripts (replacement with same file name) 
       I deregister > register new one > then enqueue (register with the five arguments
       and enqueue just with file name as handle)
    2. For my new codes valid for whole website I register them and then enqueue
    3. For my new codes for specific pages (enqueued conditionally) I directly enqueue
       them (with handle , path)
    4. In general I enqueue / register multiple codes per single function, keeping 
       them separately when I need to give some priority to the “`add_action(hook)`”.
 * I kindly ask if my above methods (from 1 to 4) are the appropriate ones according
   to recent standards of WP: in my opinion it is useful to clarify for everyone(
   thanks in advance).
 * (PS: I also repeat that, even if recently applied the deregister/register method,
   if you change a theme script is assets/js using the same script name, the parent’s
   script is automatically overridden by the child’s script .. hence it results 
   to me that using parallel paths with same structure the deregistration process
   is automatic)
 * Mauro
    -  This topic was modified 3 years ago by [Mauro Vicariotto](https://wordpress.org/support/users/mrosfy/).
      Reason: addition of Post Scriptum

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Ryan Welcher](https://wordpress.org/support/users/welcher/)
 * (@welcher)
 * [3 years ago](https://wordpress.org/support/topic/wp_register-wp_enqueue/#post-16764985)
 * Hello Mauro!
 * > To override previous parent theme scripts (replacement with same file name)
   > I deregister > register new one > then enqueue (register with the five arguments
   > and enqueue just with file name as handle)
 * This sounds like the correct approach to me. Please keep in mind that you may
   remove some functionality inherited from the parent theme by removing scripts
   it enqeues.
 * > For my new codes valid for whole website I register them and then enqueue
 * It’s not necessary to call both functions in this case. It’s perfectly fine (
   and simpler) to use `wp_enqueue_script` and provide all of the parameters. Behind
   the scenes, it will register the script and enqueue it.
 * > For my new codes for specific pages (enqueued conditionally) I directly enqueue
   > them (with handle , path)
 *  If you need to separate the process of registration and enqueuing, you can use`
   wp_register_script` to register and then call `wp_enqueue_script` later using
   only the `handle` parameter that was passed to `wp_register_script`
 * For example
 *     ```wp-block-code
       function register_some_scripts() {
       	// Register the first script.
       	wp_register_script(
       		'my-script-one',
       		'{PATH_TO}/script-one.js',
       		array(),
       		'1.0'
       	);
   
       	// Register the second script.
       	wp_register_script(
       		'my-script-two',
       		'{PATH_TO}/script-two.js',
       		array(),
       		'1.0'
       	);
       }
       add_action( 'wp_enqueue_scripts', 'register_some_scripts' );
       ```
   
 * Then call the following to enqueuing the script. This would appear in your conditional
   statement or template.
 *     ```wp-block-code
       wp_enqueue_script( 'my-script-one' );
       ```
   
 * > In general I enqueue / register multiple codes per single function, keeping
   > them separately when I need to give some priority to the “`add_action(hook)`”.
 * This sounds OK to me. If you’re using priority to control the order scripts are
   being loaded, you may want to consider using the `deps` parameter for both functions
   instead.
 * I’ll drop the link to the documentation for these functions here for reference:
    - [wp_register_script](https://developer.wordpress.org/reference/functions/wp_register_script/)
    - [wp_enqueue_script](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)
 *  I hope this helps!
 *  Thread Starter [Mauro Vicariotto](https://wordpress.org/support/users/mrosfy/)
 * (@mrosfy)
 * [3 years ago](https://wordpress.org/support/topic/wp_register-wp_enqueue/#post-16765399)
 * Thank you Ryan .. will follow

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wp_register wp_enqueue’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/twentyseventeen/4.1/screenshot.
   png)
 * Twenty Seventeen
 * [Support Threads](https://wordpress.org/support/theme/twentyseventeen/)
 * [Active Topics](https://wordpress.org/support/theme/twentyseventeen/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/twentyseventeen/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/twentyseventeen/reviews/)

## Tags

 * [deregister](https://wordpress.org/support/topic-tag/deregister/)
 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [register](https://wordpress.org/support/topic-tag/register/)

 * 2 replies
 * 2 participants
 * Last reply from: [Mauro Vicariotto](https://wordpress.org/support/users/mrosfy/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/wp_register-wp_enqueue/#post-16765399)
 * Status: resolved