Title: how do you use wp_enqueue_script
Last modified: August 19, 2016

---

# how do you use wp_enqueue_script

 *  Resolved [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/)
 * I want to use the wp_enqueue_script but I just can’t figure it out.
    I’ve been
   all over the codex and this forum trying to sort it and no luck.
 * Can someone help me out? By answering some questions:
 * All I have to do is replace the :
    `<script type="text/javascript" src="http://
   code.jquery.com/jquery-1.5.2.min.js" ></script>` with `<?php wp_enqueue_script('
   jquery' ); ?>` in the head of the header.php file?
 * Should I be putting something in my functions.php file?
    It seems like I need
   to define/register these scripts somewhere for this to work?
 * Thanks, any help appreciated!

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067010)
 * No – you add the enqueue to your functions.php file and then hook it to an [action](http://codex.wordpress.org/Plugin_API/Action_Reference)
   such as `template_redirect`. See [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 *  Thread Starter [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067243)
 * Thanks for your patience esmi.. just to recap:
 * in my functions php file I add:
 *     ```
       <?php
       function my_init_method() {
           wp_register_script( 'jquery', 'http://code.jquery.com/jquery-1.5.2.min.js');
       	wp_register_script( 'nivo', '<?php bloginfo('template_url'); ?>/scripts/slimbox2.js');
       	wp_register_script( 'slimbox', '<?php bloginfo('template_url'); ?>/scripts/slimbox2.js');
       	wp_register_script( 'picasa', '<?php bloginfo('template_url'); ?>/scripts/jquery.EmbedPicasaGallery.js');
       	wp_register_script( 'pwi', 'php bloginfo('template_url'); ?>/scripts/jquery.pwi-min.js');
       	wp_register_script( 'swf', '<?php bloginfo('template_url'); ?>/scripts/jquery.swfobject.1-1-1.min.js');
       	wp_register_script( 'simpletube', '<?php bloginfo('template_url'); ?>/scripts/jquery.simpletube.js');
       	wp_register_script( 'jqvalidate', '<?php bloginfo('template_url'); ?>/scripts/jquery.jqvalidate.js');
       }    
   
       add_action('init', 'my_init_method');
       ?>
       ```
   
 * then in my header file I just call these scripts by using:
 *     ```
       <?php wp_enqueue_script("jquery"); ?>
       <?php wp_enqueue_script("nivo"); ?>
       <?php wp_enqueue_script("slimbox"); ?>
       <?php wp_enqueue_script("picasa"); ?>
       <?php wp_enqueue_script("pwi"); ?>
       <?php wp_enqueue_script("swf"); ?>
       <?php wp_enqueue_script("simpletube"); ?>
       <?php wp_enqueue_script("jqvalidate"); ?>
       ```
   
 * correct?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067249)
 * You call the scripts in the header file. Enqueuing them in functions.php adds
   them to the HEAD section of all pages. Example – adding a jQuery accordion script
   to all front facing pages:
 *     ```
       // Add accordian menu
       if ( !function_exists( 'emporium_init_accordian' ) ) :
       function emporium_init_accordian() {
           wp_enqueue_script('accordian',
           get_template_directory_uri() . '/library/accordian-menu.js',
           array('jquery'),
           '3.0.2'
           );
       }
       endif;
       if( !is_admin() ) add_action('template_redirect', 'emporium_init_accordian');
       ```
   
 *  Thread Starter [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067250)
 * So as long as I create a function for each script into my functions.php file 
   then I should not have to call any scripts in my head, they will just automagically
   be there?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067276)
 * You don’t have to create a separate function for every script. You can enqueue
   multiple scripts within a single function if that works for you. The example 
   above was kept separate for various reasons.
 * And, yes, all enqueued scripts will be available. The enqueue ensures that they
   are called in the HEAD section of a page.
 *  Thread Starter [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067329)
 * Thanks again Esmi,
    After reading up about this on some more blogs I feel like
   I am really close to getting it working, but all I am getting is a blank white
   screen at this point.
 * This is what I have inserted into the bottom of my functions file:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * What am I doing wrong?
 *  Thread Starter [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067331)
 * Nvm Esmi,
    Thanks for your patience. It was a syntax error.

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

The topic ‘how do you use wp_enqueue_script’ is closed to new replies.

## Tags

 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * 7 replies
 * 2 participants
 * Last reply from: [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/how-do-you-use-wp_enqueue_script/#post-2067331)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
