0
votes

Is there any disadvantage to using wp_footer as the hook when enqueuing javascript files in a wordpress theme? I have about 5 files that I want to be enqueued in the footer but setting the wp_enqueue_script property for footer to true isn't doing anything.

I have wp_footer() in my footer file and when I change the action to:

add_action('wp_footer', 'extra_scripts');

the scripts load fine in the footer. This is just for a demo and not anything more than just a front end display. Is there anything wrong with doing it this way to load the scripts in the footer?

1
anyone have an idea about this? - BRAINBUZZ media

1 Answers

0
votes

You should enque what you can in the footer. To force this use:

// force all JS to the footer
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);

This way you can use the default wp_enqueue_scripts
Do remember that some scritps need to be in the <head> like the HTML5 script of twentyeleven/twentyten