Load jQuery in the WordPress footer

function pwcc_jquery_to_footer( &$wp_scripts ) {
  if ( is_admin() ) {
  }  /* 
  Move jQuery to the HTML footer 
  This should be fine but may cause problems with some plugins as it potentially breaks backward compatibility. Well coded plugins should be good.

  $wp_scripts->add_data( 'jquery',         'group', 1 ); 
  $wp_scripts->add_data( 'jquery-core',    'group', 1 ); 
  $wp_scripts->add_data( 'jquery-migrate', 'group', 1 ); 
add_action( 'wp_default_scripts', 'pwcc_jquery_to_footer' );

function pwcc_action_enqueue_assets() {
  Enqueue a file which depends on jQuery

  This is the standard technique, the difference been it names jquery-core.

   This  doesn't load the jQuery-migrate script for backward compatibility. This does require keeping up with jQuery development to ensure you remove calls to deprecated jQuery functions.
    'pwcc-scripts',       // handle
    '/path/file.js',      // source
    array('jquery-core'), // only jQuery, no jQuery-migrate
    '20150530-31',        // version
    true                  // load in footer
add_action( 'wp_enqueue_scripts', 'pwcc_action_enqueue_assets' );

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.