How to Load Plugin JS in theme’s footer section

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.

Read More

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

Related posts

Leave a Reply

1 comment

  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