Support » Fixing WordPress » javascript in header not working

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

    (@esmi)


    Forum Moderator


    danielle_r

    (@danielle_r)


    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

    (@esmi)


    Forum Moderator


    Are you enqueuing your script?

    danielle_r

    (@danielle_r)


    no

    esmi

    (@esmi)


    Forum Moderator


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

    danielle_r

    (@danielle_r)


    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
    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.