WordPress.org

Support

Support » Plugins and Hacks » Use Google Libraries » [Resolved] [Plugin: Use Google Libraries] Loading jQuery in footer

[Resolved] [Plugin: Use Google Libraries] Loading jQuery in footer

  • 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('jquery');
        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?

    http://wordpress.org/extend/plugins/use-google-libraries/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jason Penney

    @jczorkmid

    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.

    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.

    Plugin Author Jason Penney

    @jczorkmid

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

    wpengineer just posted an article on how to solve this:

    <?php
    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] [Plugin: Use Google Libraries] Loading jQuery in footer’ is closed to new replies.
Skip to toolbar