Title: Adding custom javascript
Last modified: August 30, 2016

---

# Adding custom javascript

 *  Resolved [bithons](https://wordpress.org/support/users/bithons/)
 * (@bithons)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-javascript/)
 * Hi,
 * I am trying to add my custom javascript with this code in my functions.php from
   my child-theme.
 *     ```
       function my_custom_scripts() {
       	wp_register_script( 'custom.js', get_stylesheet_directory_uri() . '../js/custom.js', array( 'jquery' ) );
       	wp_enqueue_script('custom.js');
       }
   
       add_action('wp_enqueue_scripts', 'my_custom_scripts');
       ```
   
 * It is loading my script, because I can see my console.log messages in the console,
   but it is not loading the jquery dependency. Why is this happening?
 * I hope you guys can help me out with this weird problem.

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

 *  Thread Starter [bithons](https://wordpress.org/support/users/bithons/)
 * (@bithons)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-javascript/#post-6742441)
 * I fixed the problem I will explain it later, I set the topic status on resolved
   so people don’t take the time for a problem that is already solved.
 * I will edit this message with the explanation.
 *  Thread Starter [bithons](https://wordpress.org/support/users/bithons/)
 * (@bithons)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-javascript/#post-6742694)
 * The solution was wrapping my custom javascript code in in:
 *     ```
       (function($){
           // your code here.
       })(jQuery);
       ```
   
 * For more information see: [Click here](http://wordpress.stackexchange.com/questions/174316/why-are-some-custom-javascript-files-working-but-some-are-not)
 * And for more information about proper way loading the Javascript see the this
   article what helped me with a clear explanation: [Click here](https://ithemes.com/2015/02/17/adding-scripts-wordpress-right-way/)

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

The topic ‘Adding custom javascript’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [how](https://wordpress.org/support/topic-tag/how/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [js](https://wordpress.org/support/topic-tag/js/)
 * [to](https://wordpress.org/support/topic-tag/to/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)
 * [wp_register_script](https://wordpress.org/support/topic-tag/wp_register_script/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [bithons](https://wordpress.org/support/users/bithons/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-javascript/#post-6742694)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
