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 working on optimizing my theme so that the load time can be decreased, as of now i have used wp_enqueue_script() to add my custom js file and everything is working fine as expected.

One thing which i am not very well aware of, the way plugin hook there js and css files. I want to force plugin to add there java-script files on the footer section of my theme, currently they are being loaded in the header section.

Can anyone help me to understand how this can be done (if possible).

share|improve this question

1 Answer 1

The available input parameters of wp_enqueue_script() are:

<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>

where $in_footer is false by default. If you set it as true then the script will be placed into the footer, but you will need to have wp_footer() in your theme.

You should check out the Codex for more info:

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

Update:

Here is how it's done in the plugin JavaScript to Footer to move all the javascript files from the header 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);

See the plugin source:

http://plugins.svn.wordpress.org/footer-javascript/trunk/footer-javascript.php

share|improve this answer
    
is there any way to load all scripts in the footer like wp_enqueue_script(true) and it should load everything in footer? –  Umesh Awasthi Apr 4 '13 at 15:04
    
I updated the answer –  birgire Apr 5 '13 at 9:20

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.