Title: javascript in header not working
Last modified: August 20, 2016

---

# javascript in header not working

 *  Resolved [danielle_r](https://wordpress.org/support/users/danielle_r/)
 * (@danielle_r)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/)
 * Hi all,
 * I’m trying to get a rather simple javascript to work. I first tried to put it
   directly in the <head> tag of header.php. The script did not respond. Then I 
   tried to put it in a separate .js file. No response either.
    This seems very 
   basic stuff but I just can’t reach the javascript somehow. The script is here:
   [http://werkplaatsvandestilte.nl/wp-content/themes/twentyeleven-wvds/js/custom.js](http://werkplaatsvandestilte.nl/wp-content/themes/twentyeleven-wvds/js/custom.js)(
   I’m now only testing the function with the alert for starters.) The link to activate
   the script is here (please scroll to the bottom op the page and click the link“
   reageren”): [http://werkplaatsvandestilte.nl/2011/12/06/nog-een-nieuws-item/](http://werkplaatsvandestilte.nl/2011/12/06/nog-een-nieuws-item/)
 * What am I doing wrong or have I overlooked?
    Any help would be greatly appreciated,
   tia, danielle

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/#post-2498091)
 * See [Using Javascript](http://codex.wordpress.org/Using_Javascript).
 *  Thread Starter [danielle_r](https://wordpress.org/support/users/danielle_r/)
 * (@danielle_r)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/#post-2498121)
 * Hi esmi,
    Thanks for your reply. I’ve looked there of course. Are you pointing
   me there because I’ve made a mistake? Because as far as I can see I’ve done as
   they explained in both cases… The only thing that wasn’t working for me was php
   bloginfo(‘template_url’) The header.php is in a child template and using the 
   bloginfo function would point to the parent template. So I’ve hard coded the 
   url in. Perhaps I should have mentioned earlier that the code does show, it just
   isn’t functioning.
 * Thanks for any further help, danielle.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/#post-2498128)
 * Are you enqueuing your script?
 *  Thread Starter [danielle_r](https://wordpress.org/support/users/danielle_r/)
 * (@danielle_r)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/#post-2498170)
 * no
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/#post-2498176)
 * Then try re-reading the page at the link I posted above.
 *  Thread Starter [danielle_r](https://wordpress.org/support/users/danielle_r/)
 * (@danielle_r)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/#post-2498351)
 * After trying all kinds of variations with enqueuing that didn’t work this did
   the trick for me:
 *     ```
       if(is_singular()) { ?>
           <script language="javascript">
       	function test(){
       		alert("works!")
       	}
       	</script>
       	<?php
       	}
       ```
   
 * It’s in the header.php before the wp_head() call. I found this thread very helpful:
   [http://wordpress.org/support/topic/how-to-load-specific-java-script-on-specific-page?replies=9](http://wordpress.org/support/topic/how-to-load-specific-java-script-on-specific-page?replies=9)
   
   Hope this helps someone, danielle.

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

The topic ‘javascript in header not working’ 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/)
 * 6 replies
 * 2 participants
 * Last reply from: [danielle_r](https://wordpress.org/support/users/danielle_r/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-in-header-not-working/#post-2498351)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
