Use Google Libraries
[resolved] Loading jQuery in footer (5 posts)

  1. jancbeck
    Posted 3 years ago #

    Is there a way to make UGL load the library scripts in the footer of the page? I'm using this code to call jQuery before my other scripts.

    function theme_ressources() {
        wp_enqueue_script('init', get_template_directory_uri() . '/js/init.js', array('jquery'), '1.0', true );
        // moar
    add_action('wp_enqueue_scripts', 'theme_ressources');

    However this puts jQuery in the <head> of my page. I'd like to place all my scripts before the closing </body> Tag.
    What do I have to do to print jQuery and all following script to the bottom of my page?


  2. Jason Penney
    Plugin Author

    Posted 3 years ago #

    It's up to you where you want your script to be loaded (header/footer). It's up to WordPress core where jQuery is loaded, and currently it's required to be in the header. UGL does not let you change this because it would break WordPress.

  3. jancbeck
    Posted 3 years ago #

    But loading it in footer of my theme will neither break my theme nor WordPress' admin interface. From my perspective it makes sense to let me define where stuff is placed in my theme.
    However, this is probably a minor issue since we are talking about Google CDN that hopefully gets cached in the users browser anyway plus since its a different hostname parallel download limits should be no problem.

  4. Jason Penney
    Plugin Author

    Posted 3 years ago #

    That's outside the scope of what I want UGL doing. WordPress Core makes that decision, and UGL abides by it.

  5. jancbeck
    Posted 3 years ago #

    wpengineer just posted an article on how to solve this:

    add_action( 'wp_default_scripts', 'ds_enqueue_jquery_in_footer' );
     * Plugin Name: Enqueue jQuery in Footer
     * Version:     0.0.1
     * Plugin URI:  http://wpgrafie.de/836/
     * Description: Prints jQuery in footer on front-end.
     * Author:      Dominik Schilling
     * Author URI:  http://wpgrafie.de/
    function ds_enqueue_jquery_in_footer( &$scripts ) {
    	if ( ! is_admin() )
    		$scripts->add_data( 'jquery', 'group', 1 );

    This changes the behavior of the default script registration so jQuery is loaded in footer. It goes without saying that you should test if this breaks any functionality for your plugins before using it in production.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Use Google Libraries
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic