Title: jQuery
Last modified: June 22, 2017

---

# jQuery

 *  [benjaminsaarde](https://wordpress.org/support/users/benjaminsaarde/)
 * (@benjaminsaarde)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/jquery-31/)
 * Hi,
    I have now used three days trying to find tutorials on Google, but I just
   can’t make it work. 1. How do I write jQuery​ in my functions.php in my child
   theme? 2. When that is working how do I implement the jQuery plugin: Select2.
 * My php and jQuery skills are very bad. And I am very new in the WordPress development
   university, but I really need this jQuery plugin. I use the OceanWP theme.
    Thank
   you.

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

 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [8 years, 11 months ago](https://wordpress.org/support/topic/jquery-31/#post-9253845)
 * Hi there [@benjaminsaarde](https://wordpress.org/support/users/benjaminsaarde/)
   and welcome!
 * I hope I can help you out in learning a little bit with this reply.
 * First things first. As a general rule of thumb, you want to avoid mixing the 
   two. This will, of course, vary on what you are trying and wanting to do. Ideally,
   any jQuery or JavaScript file will need to be enqueued. This can be done using`
   wp_enqueue_script()` ( [https://developer.wordpress.org/reference/functions/wp_enqueue_script/](https://developer.wordpress.org/reference/functions/wp_enqueue_script/))
   and then depending on where you want it to show, you would use the appropriate
   hook. For front-end you use the `wp_enqueue_scripts` action hook and for anything
   in the back-end, you would use `admin_enqueue_scripts`
 * Do keep in mind this can be done in either a plugin or theme – and from the looks
   you may want to look into using a child theme if you haven’t already.
 * Any other questions, please do ask.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/jquery-31/#post-9256487)
 * Adding a couple details to Jose’s great advice. These resolve common problems
   people run into with jQuery in WP.
 * As Jose points out, your jQuery script needs to be enqueued. When doing so, be
   sure to pass at least `['jquery']` as a dependency. You may require other jQuery
   libraries besides this, add them to this array too. This causes WP to load its
   local jQuery library. A lot of tutorials will tell you to load jQuery from an
   external CDN. This is not for WP, do not do this, it will conflict with the WP
   version.
 * The WP jQuery runs in noConflict mode, which makes the usual `$` shortcut invalid.
   Any place a script uses `$`, it needs to be replaced with `jQuery`. Alternately,
   create a [noConflict wrapper](https://developer.wordpress.org/reference/functions/wp_enqueue_script/#user-contributed-notes)(
   first note after the jump) that declares `$` as a valid shortcut.
 *  [arditmorina](https://wordpress.org/support/users/arditmorina/)
 * (@arditmorina)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/jquery-31/#post-9354499)
 * [@benjaminsaarde](https://wordpress.org/support/users/benjaminsaarde/) I use 
   this code in functions.php in child theme and it works correctly:
 * //Making jQuery to load from Google Library
    function replace_jquery() { if (!
   is_admin()) { // comment out the next two lines to load the local copy of jQuery
   wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, ‘[https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js&#8217](https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js&#8217);,
   false, ‘1.12.4’); wp_enqueue_script(‘jquery’); } } add_action(‘init’, ‘replace_jquery’);

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

The topic ‘jQuery’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 4 participants
 * Last reply from: [arditmorina](https://wordpress.org/support/users/arditmorina/)
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/jquery-31/#post-9354499)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
