Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to place my_javascript_file in the footer. According to the documentation $in_footer is the fifth value and it is a boolean so I have it set to true. Currently it doesn't show up anywhere, as far as I can tell from inspecting the code.

Got it to work, it was hidden in a div I forgot to close (oops)

UPDATE added fourth parameter as empty string ' '

FUNCTIONS.PHP FILE

<?php
function load_scripts() {
   wp_enqueue_script('jquery');
   wp_enqueue_script('my_javascript_file', get_template_directory_uri() . '/javascripts/app.js', array('jquery'),' ',true);
}    

add_action('init', 'load_scripts');
/*add_action('wp_footer', 'load_scripts');/*DELETED THIS PART
?>

FOOTER.PHP added wp_footer

</div>
    <!-- Main Row Ends -->
<?php wp_footer(); ?> /*added*/
</body>

</html>
share|improve this question
    
No need to enqueue jQuery, you're supplying it as a dependency already, it will be included. Doesn't make sense to add load_scripts on wp_footer action, it comes too late, when all scripts have been enqueued already. –  soulseekah Mar 11 '12 at 19:46
    
You theme does not call wp_footer(), does it? The $in_footer parameter documentation goes on to state that ""This requires the theme to have the wp_footer() hook in the appropriate place."" –  soulseekah Mar 11 '12 at 19:47
    
@Soulseekah when you say supplying it as a dependancy already are you referring to the array(jquery) my theme does call wp_footer. I have added the footer.php file above now. –  Anders Kitson Mar 11 '12 at 19:52
    
You are not calling wp_footer, right now you're adding a non-existing function to the wp_footer action. Replace that line with wp_footer() and that's it. wp_enqueue_script('jquery'); is not required, you are already including jquery as a dependency (array('jquery')), cleaner code. –  soulseekah Mar 11 '12 at 19:57
    
@Soulseekah I added wp_footer to my footer.php file, but it still isn't working do I need the add_action in my functions.php file, I have tried with and without and it doesn't work still. –  Anders Kitson Mar 11 '12 at 20:01
show 2 more comments

1 Answer

up vote 5 down vote accepted

You have true set in the 4th parameter (version), not the 5th.

wp_enqueue_script(
    'my_javascript_file',                                 //slug
    get_template_directory_uri() . '/javascripts/app.js', //path
    array('jquery'),                                      //dependencies
    false,                                                //version
    true                                                  //footer
);

Also, as someone else mentioned, drop jquery enqueue, you've got it as a dependency, you don't need to enqueue it as well.

One last thing, your function name has a good chance of breaking your site somewhere down the line. load_scripts has a pretty large chance of conflicting with something from the core or from the theme/plugin.

share|improve this answer
    
Ok I have dropped the query. Ill change the function name, thanks for the suggestion. But this still doesn't work. I copied and pasted your script even. I copied old code so my version did have the parameter as the 5th. Also do I need the add action for wp_footer –  Anders Kitson Mar 11 '12 at 20:14
    
Shouldn't make a difference where it's enqueued. Does it enqueue properly if you set $in_footer to true. –  m0r7if3r Mar 11 '12 at 20:17
    
Also //version is a string so should I not be placing empty quotes '' instead of false –  Anders Kitson Mar 11 '12 at 20:18
    
I thought that $in_footer is set to true already. –  Anders Kitson Mar 11 '12 at 20:20
    
My bad, I meant set $in_footer to false. $version's default value is false, it sets the version to the current version of wordpress. If you want no version, pass in NULL. Have you read the codex page about this function? –  m0r7if3r Mar 11 '12 at 20:28
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.