WordPress jquery on footer

In this file

wp-include/script-loader.php

Read More

Have this code:

$scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.11.3');
$scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.11.3');
$scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '1.2.1');

How do I put the jquery in the footer?

I’ve tried adding a fifth parameter “true” or “1”, but does not work.

...
 * Localizes some of them.
 * args order: $scripts->add( 'handle', 'url', 'dependencies', 'query-string', 1 );
 * when last arg === 1 queues the script for the footer
...

I want to put the jquery at the bottom because it is blocking the correct page load (google page speed recommendation).

Related posts

3 comments

  1. You have to dequeue it first and then enqueue it again.
    The following code will do exactly what you need.

    function jquery_mumbo_jumbo()
    {
        wp_dequeue_script('jquery');
        wp_dequeue_script('jquery-core');
        wp_dequeue_script('jquery-migrate');
        wp_enqueue_script('jquery', false, array(), false, true);
        wp_enqueue_script('jquery-core', false, array(), false, true);
        wp_enqueue_script('jquery-migrate', false, array(), false, true);
    }
    add_action('wp_enqueue_scripts', 'jquery_mumbo_jumbo');
    
  2. After experiencing all these problems and testing workarounds myself without any joy, I decided to just migrate all scripts in one go.

    So how about going one better and having some code that loads all your script files, present and future into the footer. Preventing this ballache from repeating. Also handy for any plugins you may add.

    Open your functions.php file and add this bad boy

    // Script to move all Head scripts to the Footer
    
    function remove_head_scripts() { 
       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); 
    } 
    add_action( 'wp_enqueue_scripts', 'remove_head_scripts' );
    
    // END of ball ache
    

Comments are closed.