-1

I'm trying to modify a plugin for enqueue scripts in the footer, because my jQuery link is in the footer.

The plugin:

add_action('wp_enqueue_scripts', 'fjgwpp_addCSSandJS');
function fjgwpp_addCSSandJS() {

    //Register scripts
    wp_register_script(
        'justifiedGallery', 
        plugins_url('js/jquery.justifiedGallery.min.js', __FILE__)
    );
    wp_register_script(
        'flickrJustifiedGalleryWPPlugin', 
        plugins_url('js/flickrJustifiedGalleryWPPlugin.js', __FILE__)
    );
    wp_register_script(
        'colorbox', 
        plugins_url('lightboxes/colorbox/jquery.colorbox-min.js', __FILE__)
    );

    if (fjgwpp_getOption('provideSwipebox')) {
        wp_register_script(
            'swipebox', 
            plugins_url('lightboxes/swipebox/js/jquery.swipebox.min.js', __FILE__)
        );
    }

    //Enqueue scripts
    wp_enqueue_script('jquery');
    wp_enqueue_script('justifiedGallery');
    wp_enqueue_script('flickrJustifiedGalleryWPPlugin');
    if (fjgwpp_getOption('provideColorbox')) {wp_enqueue_script('colorbox');
    }
    if (fjgwpp_getOption('provideSwipebox')) {
        wp_enqueue_script('swipebox');
    }
}

I tried to set $in_footer = true for all wp_register_script and wp_enqueue_script like this:

wp_enqueue_script('justifiedGallery', true);

But the scripts are still printing inside the <head>.

UPDATE

I change wp_register_script for:

wp_register_script('flickrJustifiedGalleryWPPlugin', plugins_url('js/flickrJustifiedGalleryWPPlugin.js', __FILE__), '', '', true);

And now the scripts are loaded on footer. But appears an error: Uncaught ReferenceError: jQueryFJGWPP is not defined

  • The edit you've provided doesn't seem to be caused by any of the code you've posted. Can you start a new question? And it looks like that's a PHP error, it probably belongs on the regular StackExchange site. – guiniveretoo Feb 12 '15 at 20:15
5

From http://codex.wordpress.org/Function_Reference/wp_register_script:

<?php wp_register_script( $handle, $src, $deps, $ver, $in_footer ); ?>

This means you need to add the $deps and $ver values to wp_register_script() in order to set $in_footer. Like this:

wp_register_script(
    'justifiedGallery', 
    plugins_url('js/jquery.justifiedGallery.min.js', __FILE__),
    false, // or array(), or array('jquery') if this depends on jQuery
    '1.0', // or your plugin version, or the version of the js file
    true   // $in_footer
);
  • Please, see my update above. – marcelo2605 Feb 12 '15 at 20:09

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.