The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] javascript in header not working (7 posts)

  1. danielle_r
    Posted 4 years ago #

    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 (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/

    What am I doing wrong or have I overlooked?
    Any help would be greatly appreciated, tia, danielle

  2. esmi
    Forum Moderator
    Posted 4 years ago #

  3. danielle_r
    Posted 4 years ago #

    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.

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    Are you enqueuing your script?

  5. danielle_r
    Posted 4 years ago #


  6. esmi
    Forum Moderator
    Posted 4 years ago #

    Then try re-reading the page at the link I posted above.

  7. danielle_r
    Posted 4 years ago #

    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(){

    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
    Hope this helps someone, danielle.

Topic Closed

This topic has been closed to new replies.

About this Topic