-1

I have tried every way I know about, and have read about, to move the jquery library to the footer including the following and every possible variation of the following:

function add_scripts() {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3', true);
        wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'add_scripts');

and

wp_enqueue_script('jquery','/wp-includes/js/jquery/jquery.js','','',true);

I'm not sure what version(s) of Wordpress these worked in but they don't work in the latest versions (3.5 - 3.7). Of course jquery can be deregistered or completely deleted from the script-loader.php file and then hard coded into the footer but the script will not work. WordPress somehow prevents it from actually loading even though the code to do so is sitting there in the html. Before anyone says this, while I am attempting to load jquery in the footer, all other javascript will be loaded afterwards so it a question of jquery dependent scripts loading prior to the library. Also, many of people will say that its not good to load core scripts in the footer which, from a best practices standpoint, may be true but this is irrelevant because Google wants it in the footer and that is all that really matters. Any suggestions will be appreciated.

1

Use the 5th parameter when using the wp_enqueue_script function:

Normally, scripts are placed in <head> 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

-2

I did this in my functions.php file and it worked. Of course, you need wp_footer() just above the closing tag in your footer.php file:

function load_jquery_file () {
    wp_enqueue_script( 'jquery' );
}

 add_action( 'wp_footer', 'load_jquery_file' );
  • 1
    Never add styles and scripts directly to wp_head or wp_footer. There is a specific hook for that, wp_enqueue_scripts – Pieter Goosen Oct 23 '14 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.