user1110237
user1110237

Reputation: 99

Make one of my many JS scripts load in the footer (wordpress)

From my previous problem I have discovered I have to move one single plugins script to be loaded in the footer rather then the header (o other items can load first)

Is there a way (either in wordpress, or the actually plugin) to tell it to send one plugin to load in the footer somewhere? Maybe the location where ever it gives instructions to load in the header can be changed?

Upvotes: 0

Views: 276

Answers (2)

Joseph Silber
Joseph Silber

Reputation: 219936

The last argument for wp_enqueue_script is a Boolean whether to load the script in the footer:

Normally scripts are placed in the <head> section. If this parameter is true the script is placed at the bottom of the <body>. This requires the theme to have the wp_footer() hook in the appropriate place. Note that you have to enqueue your script before wp_head is run, even if it will be placed in the footer.

http://codex.wordpress.org/Function_Reference/wp_enqueue_script


So, use this before the head is outputted:

wp_enqueue_script( 
    'handle_name',
    'source/file/path',
    array('some_dependency'),
    '1.0'
    true // <-- this is what sends it down to the footer
);

Then add wp_footer() before closing off the body:

<?php wp_footer(); ?>
</body>
</html>

Upvotes: 3

Sinetheta
Sinetheta

Reputation: 9429

wp_enqueue_script with $in_footer

Example usage

wp_enqueue_script('wp-polls', plugins_url('wp-polls/polls-js.js'), array('jquery'), '2.50', true);

Upvotes: 0

Related Questions