Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress jquery on footer

In this file

wp-include/script-loader.php

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).

like image 918
Giest Avatar asked Feb 27 '16 00:02

Giest


1 Answers

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');
like image 75
Igor Yavych Avatar answered Nov 09 '22 22:11

Igor Yavych