Title: External Javascript not working
Last modified: August 19, 2016

---

# External Javascript not working

 *  Resolved [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/external-javascript-not-working/)
 * I want to tidy my header.php file up a bit and so I’m creating a custom.js file
   to add all of the lose javascript etc. The problem is when it’s in the header
   it works okay but if I then add it to an external file and link to that from 
   the header it doesn’t work?
 * For example I’m using
 * `<script type="text/javascript" src="<?php bloginfo( 'template_directory' ); ?
   >/scripts/custom.js"></script>`
 * to call the javascript and it’s linking correctly but the code isn’t working.
   An example of the code not working:
 *     ```
       jQuery(document).ready( function($) {
       	$('#access > li:last-child').addClass('last-item');
       } );
       ```
   
 * I’ve tried moving the location of the link around the head tags but nothing!
 * Any help would be very much appreciated.

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

 *  [sabinou](https://wordpress.org/support/users/sabinou/)
 * (@sabinou)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072386)
 * Can you try with an absolute URL for the javascript location, instead of a relative
   URL ?
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072389)
 * Thanks for your help. But what I’m currently using (the code above) converts 
   that into absolute path to the script?! I’ve tried typing in the actual url to
   the script, just in case that wasn’t working, but that still doesn’t work.
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072808)
 * Bump
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072812)
 * Please try searching the Codex.
    [http://codex.wordpress.org/Using_Javascript](http://codex.wordpress.org/Using_Javascript)
   [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072813)
 * Thanks for your help but I’ve added the script as per their example:
 * `<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/pathto/
   yourscript.js"></script>`
 * And it still doesn’t work. The only way I can get it to work is by adding the
   actual script to the header file but that’s gonna get very messy when I want 
   to add more and more scripts!
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072905)
 * Anyone?
 *  [gtquila](https://wordpress.org/support/users/gtquila/)
 * (@gtquila)
 * [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072913)
 * Hi there!
 * I used the same way as yours to refer to an external javascript inside my header.
   php, and it worked well for me, just now. If it’s not working, maybe it’s your
   script that has a problem…?
 * Hmm.. Try putting an alert(‘any string’) to the first line of the function inside
   the script you are calling and test if an alert msg does appear. It’s what I 
   always do to check if my script’s fine.
 * Hope this could help.. 🙂
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072914)
 * Hi. Thanks for your help. What do you mean about adding an alert to the first
   function?
 *  [Travis Northcutt](https://wordpress.org/support/users/travisnorthcutt/)
 * (@travisnorthcutt)
 * [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072915)
 * gtquila means you should add some code to your javascript file (like an alert
   box) to confirm that it’s working.
 * [http://www.w3schools.com/JS/js_popup.asp](http://www.w3schools.com/JS/js_popup.asp)
 *  [gtquila](https://wordpress.org/support/users/gtquila/)
 * (@gtquila)
 * [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072916)
 * My _header.php_:
 *     ```
       ...
       <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/plugins/js/form-checker.js"></script>
       ...
       ```
   
 * Somewhere in my _sidebar.php_:
 *     ```
       ...
       <form..onsubmit="return validateForm()">
       </form>
       ...
       ```
   
 * My script inside _template\_url_/plugins/js/form-checker.js:
 *     ```
       ...
       function validateForm(){
       alert("test")
       }
       ...
       ```
   
 * That’s it!
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072917)
 * Thanks so much to both of you. I just added a checker script and managed to find
   the problem. It was a function that I’d included that decided to break everything
   else! Good idea though to add a very simple script and make sure that’s working
   fully in order to check more complex scripts.
 *  [gtquila](https://wordpress.org/support/users/gtquila/)
 * (@gtquila)
 * [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072919)
 * Glad to have helped! 🙂

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

The topic ‘External Javascript not working’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 12 replies
 * 5 participants
 * Last reply from: [gtquila](https://wordpress.org/support/users/gtquila/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/external-javascript-not-working/#post-2072919)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
