danielle_r
Member
Posted 4 months 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
danielle_r
Member
Posted 4 months 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.
Are you enqueuing your script?
danielle_r
Member
Posted 4 months ago #
Then try re-reading the page at the link I posted above.
danielle_r
Member
Posted 4 months 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(){
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.