How to load jQuery in the footer – nothing works for me

I tried all the solutions I found on the internet, including the ones I found here, but nothing works on my theme – jQuery always load in header. I try to use the one from Google, but I would be happy to use the local one too, only in footer.
This is what I have now:

   function my_init() {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js?ver=1.10.2', false, '1.10.2', true);
        wp_enqueue_script('jquery');

        // load a JS file from my theme: js/theme.js
        //wp_enqueue_script('my_script', get_bloginfo('template_url') . '/js/theme.js', array('jquery'), '1.0', true);
    }
}
add_action('init', 'my_init');

Any ideas why no solution works for me?

Related posts

1 comment

  1. You need to load your scripts in the footer so you’ll need to add them to the functions.

    This method works for parent themes dependent on jQuery.

    For child themes

    Change:

    get_template_directory_uri()
    

    To

    get_stylesheet_directory_uri()
    

    Example code for parent themes:

    function wpsites_load_scripts() {
    
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
    }
    
    add_action( 'wp_enqueue_scripts', 'wpsites_load_scripts' );
    

    The 5th parameter determines where the script is loaded:

    $in_footer

    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

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

Comments are closed.