I think it should be much easier if you know the page id. You shouldn’t need all the wp_query stuff, Dave. It also depends on what the script is, because this will tell you whether you need to load it in the header or the footer. If it’s something like a facebook fancy-like-float thing—that is, not essential to the page loading—then it should be loaded in the footer, so as not to slow the page down. If it is fundamental to getting the content of the page then it will need to be in the header. Most scripts can happily be loaded in the footer, so the page is delivered quickly to the user and then the script is loaded in the microseconds during which the user’s brain is adjusting to the fact that the page arrived in their browser.
The code would be something like this:
add_action('wp_footer', 'add_my_extra_js', 100);
function add_my_extra_js(){
if ( is_page(42) ) {
?>
<script type="text/javascript">
//YOUR SCRIPT HERE
</script>
<?php
}
}
If the script is an entire file, then the process is different.
You add this to your functions.php file in your child theme. If you’ve never done this, read this article on customizing Customizr first.