Title: wp_enqueue_script problem
Last modified: August 19, 2016

---

# wp_enqueue_script problem

 *  Resolved [Lyden](https://wordpress.org/support/users/lyden/)
 * (@lyden)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_enqueue_script-problem-1/)
 * First post to WordPress forums…
 * Any ideas on why this would work:
 *     ```
       function add_header_scripts() {
       	echo '<script src="http://localhost:8888/wp-content/themes/myTheme/myScript.js" type="text/javascript"></script>';
       }
   
       add_action('wp_head', 'add_header_scripts');
       ```
   
 * But this does not:
 *     ```
       function add_header_scripts() {
       	wp_enqueue_script('my_script', 'http://localhost:8888/wp-content/themes/myTheme/myScript.js');
       }
   
       add_action('wp_head', 'add_header_scripts');
       ```
   
 * Code is in functions.php.
 * I have also tried supplying values for all possible parameters of wp_enqueue_scripts
   including using null for $ver to avoid problems with appending version numbers
   to the script url.
 * Also, I know not to hardcode the url. I will use bloginfo once this problem is
   solved.
 * Thanks in advance!

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

 *  Thread Starter [Lyden](https://wordpress.org/support/users/lyden/)
 * (@lyden)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_enqueue_script-problem-1/#post-1896023)
 * Solved it. For some reason, you can’t use the wp_head action. This is very unintuitive.
   You would think that since you include external scripts via <script> tags in 
   the head, you would use the wp_head action.
 * I changed:
    `add_action('wp_head', 'add_header_scripts');`
 * To:
    `add_action('init', 'add_header_scripts');`
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_enqueue_script-problem-1/#post-1896038)
 * Use `wp_enqueue_scripts` or `wp_print_scripts`(not `wp_head`) and the enqueue
   should work just fine.
 * If you’re finding that’s still too late(you shouldn’t do), then you can always
   use `wp` or `template_redirect`..
 * `init` fires on every page, and you have no access to conditional tags at that
   point, so it’s considered too early for enqueues(though the codex currently suggests
   otherwise, it is in fact wrongly documented).

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

The topic ‘wp_enqueue_script problem’ is closed to new replies.

## Tags

 * [First post](https://wordpress.org/support/topic-tag/first-post/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/wp_enqueue_script-problem-1/#post-1896038)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
