Search code examples
wordpressscriptingfooter

custom_functions wordpress enqueue_script in footer instead of header


I can get this to work in the header but how can I get it in the footer. I use thesis framework on my wordpress.

function load_scripts() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://code.jquery.com/jquery-1.7.2.min.js');
    wp_enqueue_script( 'jquery');
    wp_register_script( 'bootstrap', '/wp-content/themes/thesis/custom/js/bootstrap.min.js', true);
    wp_enqueue_script( 'bootstrap');
}    
add_action('wp_enqueue_scripts', 'load_scripts');

I put true and it doesn't seem to work. I've been using this as a reference. wp_enqueue_script( $handle,$src ,$deps ,$ver ,$in_footer );


Solution

  • It looks like you're passing true in the wrong place - WordPress will interpret that as the value for $deps. While $deps is optional, you need to provide it if you want to specify a subsequent parameter. The codex entry for wp_register_script tells you the default values - just pass those.

    So your wp_register_script call should be:

    wp_register_script( 'bootstrap', '/wp-content/themes/thesis/custom/js/bootstrap.min.js', array(), false, true);
    

    Probably worth using get_bloginfo to get your template directory, rather than hardcoding it too.