Title: Referencing Javascript code location in header.php properly
Last modified: August 22, 2016

---

# Referencing Javascript code location in header.php properly

 *  Resolved [Benny](https://wordpress.org/support/users/wordbob/)
 * (@wordbob)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/referencing-javascript-code-location-in-headerphp-properly/)
 * I am using some external javascript files that I reference in the **header.php**
   file with something like this (with a valid IP address used):
 * <script type=”text/javascript” src=”[http://999.999.999.999/myscripts/concode.js”></script&gt](http://999.999.999.999/myscripts/concode.js”></script&gt);
 * I know I can change them to us the domain name instead of the IP (better),but
   that also seems a little shortsighted. What’s the best way to create a dynamic
   site reference that pull the site location from the Permalinks for these?

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

 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/referencing-javascript-code-location-in-headerphp-properly/#post-5786713)
 * Are the scripts on your server, or are they elsewhere?
 *  Thread Starter [Benny](https://wordpress.org/support/users/wordbob/)
 * (@wordbob)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/referencing-javascript-code-location-in-headerphp-properly/#post-5786717)
 * Whoops… should have included that info.
 * Yes, they are on my server. Currently they are in a folder named “myscripts” 
   under the root web (e.g. public_html) but they could move into the WordPress 
   hierarchy if that simplifies things.
 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/referencing-javascript-code-location-in-headerphp-properly/#post-5786732)
 * Ok, personally I like to store any JS included with the theme in a `/js/` directory
   under the theme, because it might as well be with the theme if the theme is including
   it, and that’s what all of the WordPress default themes have done the past few
   years.
 * So, that would be this:
 * `<script src="<?php echo esc_url( get_template_directory_uri() ); ?>/js/concode.
   js"></script>`
 * In the above, it’s fetching the directory for the currently active theme (which
   means it’s independent of whichever domain you’re using, and independent of HTTP
   vs. HTTPS) then pulling `concode.js` out of the `/js/` directory in the theme’s
   directory, where the js is located at:
 * `/wp-content/themes/[current-theme]/js/concode.js`
 *  Thread Starter [Benny](https://wordpress.org/support/users/wordbob/)
 * (@wordbob)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/referencing-javascript-code-location-in-headerphp-properly/#post-5786749)
 * Thanks, that will do it!
 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/referencing-javascript-code-location-in-headerphp-properly/#post-5786756)
 * You’re welcome!

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

The topic ‘Referencing Javascript code location in header.php properly’ is closed
to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [James Huff](https://wordpress.org/support/users/macmanx/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/referencing-javascript-code-location-in-headerphp-properly/#post-5786756)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
