Title: wp_register_script and wp_enqueue_script
Last modified: August 18, 2016

---

# wp_register_script and wp_enqueue_script

 *  Resolved [tango](https://wordpress.org/support/users/tango/)
 * (@tango)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/wp_register_script-and-wp_enqueue_script/)
 * Hi,
 * I’ve a pluigin that needs to load jquery.js plus my own javascript.
 * At the moment this is done via a function that prints the <script…> tags using
   the add_action(‘wp_head’, ‘my_head_function’).
 * I’d like to move to the wp_register_script and wp_enqueue_script functions of
   wordpress in order to deal with themes or other plugins loading the same library,
   but I do not manage to get it work.
 * Can you please point at some working example where a plugin correctly load a 
   js distributed with wordpress and plugin-specific js using such functions?
 * Thanks, Sergio

Viewing 1 replies (of 1 total)

 *  Thread Starter [tango](https://wordpress.org/support/users/tango/)
 * (@tango)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/wp_register_script-and-wp_enqueue_script/#post-634732)
 * This is what I understood and that works for me:
 * in the plugin module, add something like:
 * function myplugin_init() {
    if (function_exists(‘wp_enqueue_script’)) { // for
   lirabries part of wordpress wp_enqueue_script(‘jquery’); // for new libraries
   wp_register_script(‘my_js_lib’, get_bloginfo(‘wpurl’) . ‘/wp-content/plugins/
   mypling/js/my_js_lib.js’, array(‘dep if any’), ‘version’); wp_enqueue_script(‘
   my_js_lib’); } }
 * add_action(‘init’, ‘myplugin_init’);

Viewing 1 replies (of 1 total)

The topic ‘wp_register_script and wp_enqueue_script’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [tango](https://wordpress.org/support/users/tango/)
 * Last activity: [18 years, 7 months ago](https://wordpress.org/support/topic/wp_register_script-and-wp_enqueue_script/#post-634732)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
