Title: Register and enqueue a script
Last modified: August 20, 2016

---

# Register and enqueue a script

 *  Resolved [ken90](https://wordpress.org/support/users/ken90/)
 * (@ken90)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/register-and-enqueue-a-script/)
 * Hi, I’m learning how things work in wordpress and recently I’ve learned something
   about enqueuing and registering scripts. Thing I don’t get is why do we need 
   to register a script and then enqueue it when we can just use enqueue function?
   Only practical use I see in this is deregistering and then registering a different
   version of jquery. To put it short is there any point in writing
 *     ```
       function my_jquery_script()
       {
          wp_register_script( 'my-script', get_template_directory_uri() . '/js/my-script.js', array( 'jquery' ) );
        wp_enqueue_script( 'my-script' );
       }
       add_action( 'wp_enqueue_scripts', 'my_jquery_script' );
       ```
   
 * **when we could just do this:**
 *     ```
       function my_jquery_script()
       {
         wp_enqueue_script( 'my-script', get_template_directory_uri() . '/scripts/my-script.js', array( 'jquery'), '1.0', false ); ;
       }
           add_action('wp_enqueue_scripts', 'my_jquery_script');
       ```
   

Viewing 1 replies (of 1 total)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/register-and-enqueue-a-script/#post-2943153)
 * Let’s say you have six different scripts. Some of those scripts load on only 
   a couple of pages, some load on all pages, some on half of your pages, etc. And
   there is a lot of overlap. You only want to load the scripts on the pages where
   they are needed, so you are putting them inside conditionals– `if (is_page()){...}`,
   for example.
 * If you are using `wp_enqueue_script` without `wp_register_script` you have to
   write out the whole set of parameters every time you enqueue your script. If 
   you register the script, you can enqueue it using the shorthand syntax.
 * If you need to change the version of the script, you can change it in one place
   instead of two or three or four places.
 * And as you noted, you can de-register a script, which can be convenient.

Viewing 1 replies (of 1 total)

The topic ‘Register and enqueue a script’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/register-and-enqueue-a-script/#post-2943153)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
