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 load JS files in my theme's to footer.All my custom JS files are being added to WordPress using wp_enqueue_script, but i am unable to find any way which will help me to load them in footer.

one possible way is to

remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);

but that means , I need to list down all possible JS files being used in plugins and than remove those from header and add them to footer, but that seems a bit strange to me as I need to take care what new plugin i have added or removed.

Is there any other alternate where i can let Wordpress load those JS files (including Plugin's) in footer section.

Since I can add/ remove plugin, so i am not sure how to handle it.

share|improve this question
    
What do you mean by I need to list down all possible JS files being used in plugins and than remove those from header and add them to footer. Did you test the code snippet? –  birgire Nov 17 '13 at 10:30
    
@birgire: By that i mean, I need to see what all JS files are being used and loaded by plugins. I have limited knowledge about WordPress so might be missing something –  Umesh Awasthi Nov 17 '13 at 10:33
1  
do you want to load all javascript files in the footer, both from plugins and the theme? The above code snippet should do it all for you, but maybe I'm misunderstanding the question ;-) –  birgire Nov 17 '13 at 10:35
    
@birgire:Yes that is true I want to load all JS in footer, only issue i can see with Jquery core but will be able to handle that. –  Umesh Awasthi Nov 17 '13 at 10:39
1  
While not impossible some scripts are supposed to be in header (async loaders and analytics, etc). I would never recommend to do this blindly in bulk for all scripts. –  Rarst Nov 17 '13 at 16:33

1 Answer 1

From the Codex :

$in_footer (boolean) (optional) Normally, scripts are placed in of the HTML document. If this parameter is true, the script is placed before the end tag. This requires the theme to have the wp_footer() template tag in the appropriate place.

    Default: false

So if your script is myscript.js, I'd try something like

wp_enqueue_script('myscript', bloginfo('template_url').'/js/myScript.js'__FILE__), array(), 'version', true );
share|improve this answer
    
The OP seems to be wanting to force all scripts to the footer and not just scripts under his/her control. –  s_ha_dum Nov 17 '13 at 16:22
    
Right. Then I'd use the plugins_loaded hook. Write a function that does the head removal / footer add (like the code the OP wrote, but inside a function) then use it in add_action( 'plugins_loaded', 'put_js_in_footer' ); –  AurelienT Nov 17 '13 at 21:09

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.