Title: Javascript in Custom Theme
Last modified: August 30, 2016

---

# Javascript in Custom Theme

 *  Resolved [Carlos A.](https://wordpress.org/support/users/carlos-a/)
 * (@carlos-a)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/)
 * Hi, i’m new in wordpress, i made a custom theme and i have a problem with javascript
   on my wordpress site, i used the same html and js files that i used on a joomla
   site and the js files are not working, i try to make a html with the js files
   and it works fine, the problem is when i add it to my wordpress site.
 * On the footer.php i have this
 * <script type=”text/javascript” src=”[https://external/assets/scripts/jquery.min.js”></script&gt](https://external/assets/scripts/jquery.min.js”></script&gt);
   
   <script type=”text/javascript” src=”<?php echo get_stylesheet_directory_uri();?
   >/js/portal.min.js”></script>
 * </body>
    </html>
 * if i saw the code of the site it shows that it have the js files but its not 
   working, someone please help me with this, i’m stuck here

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

 *  [Colin McDermott](https://wordpress.org/support/users/woodsandhillsplc/)
 * (@woodsandhillsplc)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522717)
 * URL?
 * I assume this is not the actual URL/code on the site?
 * “[https://external/assets/scripts/jquery.min.js&#8221](https://external/assets/scripts/jquery.min.js&#8221);
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522723)
 * Useful articles:
    - [https://codex.wordpress.org/Using_Javascript](https://codex.wordpress.org/Using_Javascript)
    - [https://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers](https://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers)
 *  Thread Starter [Carlos A.](https://wordpress.org/support/users/carlos-a/)
 * (@carlos-a)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522827)
 * Yes Colin, thats not the actual, is an ip address, for security reason don’t 
   post the ip, i’ve read a lot about adding jquery to wordpress, i saw the complete
   code that generate the wordpress and i only see my js files, so i don’t know 
   what is the problem
 *  Thread Starter [Carlos A.](https://wordpress.org/support/users/carlos-a/)
 * (@carlos-a)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522828)
 * And another question how do i add the functions.php to my theme?
    just use the
   include(get_template_directory_uri().’/js/myscript’); and where i should put 
   that?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522880)
 * When you say custom theme, did you build it from scratch or are you working from
   an existing theme?
 *  Thread Starter [Carlos A.](https://wordpress.org/support/users/carlos-a/)
 * (@carlos-a)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522886)
 * Hi Andrew, i build it from scratch.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522891)
 * You can create your functions.php file in the Notepad software if you’re using
   Windows. Just save the file with a ‘`.php`‘ extension and it will be a PHP file
   automatically. Then using which ever file transfer protocol your hosting providers
   give you, upload that functions.php file to your main theme folder. E.g.:
 *     ```
       /wp-content/themes/your-theme/functions.php
       ```
   
 * You don’t need to do this bit:
 *     ```
       <script type="text/javascript" src="https://external/assets/scripts/jquery.min.js"></script>
       ```
   
 * You can instead just call the jQuery library that WordPress is built on. This
   is already packed into your WordPress installation. To use it you need only put
   this into your functions.php file:
 *     ```
       <?php 
   
       /**
        * Proper way to enqueue scripts
        */
       function my_scripts() {
       	wp_enqueue_script('jquery');
       }
   
       add_action( 'wp_enqueue_scripts', 'my_scripts' );
   
       ?>
       ```
   
 * The jQuery library will then be automatically loaded in at the top of the page.
 * Then you can load your custom script that relies on the jQuery library, like 
   this:
 *     ```
       wp_enqueue_script( 'general', get_template_directory_uri() . '/js/myscript.js', array( 'jquery' ));
       ```
   
 * All together your functions.php code would be:
 *     ```
       <?php 
   
       /**
        * Proper way to enqueue scripts and styles
        */
       function my_scripts() {
           wp_enqueue_script('jquery');
           wp_enqueue_script( 'general', get_template_directory_uri() . '/js/myscript.js', array( 'jquery' ));
       }
   
       add_action( 'wp_enqueue_scripts', 'my_scripts' );
   
       ?>
       ```
   
 *  Thread Starter [Carlos A.](https://wordpress.org/support/users/carlos-a/)
 * (@carlos-a)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522894)
 * Thank you so much Andrew for the help, it really help me

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

The topic ‘Javascript in Custom Theme’ 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/)
 * 8 replies
 * 3 participants
 * Last reply from: [Carlos A.](https://wordpress.org/support/users/carlos-a/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/javascript-in-custom-theme/#post-6522894)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
