Title: Where should I add a javascript file
Last modified: August 20, 2016

---

# Where should I add a javascript file

 *  [viki](https://wordpress.org/support/users/sheoran8210/)
 * (@sheoran8210)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/where-should-i-add-a-javascript-file/)
 * Hello folks,
 * I have written some javascript code for something. What I want to know is, In
   which directory should I upload this file and in which file header should I embed
   javascript file name, So that I can use this code globally. I guess I will have
   to write in my theme file code but I don’t know which one. Can someone assist
   me please?
 * Thanks all.

Viewing 1 replies (of 1 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/where-should-i-add-a-javascript-file/#post-2777069)
 * Try it with wp_enqueue_script() in your theme’s functions.php.
 * [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 * Create a “js” folder inside your theme and put your javascript file inside it.
   Then use something simular to this in your theme’s functions.php:
 *     ```
       function my_javascripts_files() {
   
         // file to enqueue: my_javascript.js
   
         // directory: wp-content/themes/yourtheme/js/
   
         wp_enqueue_script('my_script', get_template_directory_uri() . '/js/my_javascript.js');
       }
       add_action('wp_enqueue_scripts', 'my_javascripts_files');
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Where should I add a javascript file’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/where-should-i-add-a-javascript-file/#post-2777069)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
