Enqueue script in footer

2 Replies ·

  1. Hi!

    I just switched from Hybrid/Skeleton to Hybrid Base, as I felt it was time to step up a bit and dive into the Hybrid Core framework. So far I love it, and being a Hybrid fan for years I have high hopes for what it’ll bring in terms of new theming knowledge.

    My first “bump in the road” is something as simple as enqueuing a custom js in the footer.

    This is what I add to the functions.php file:

    add_action( 'wp_enqueue_scripts', 'sm_include_scripts' );
    function sm_include_scripts() {
    	wp_enqueue_script( 'production.min.js', get_template_directory_uri() . '/js/production.min.js', array('jquery'), true );

    Everything works – except the fact that it loads the script in the <head> and not in the footer.

    Am I missing something obvious here, that is different from Hybrid to Hybrid Base?

  2. admin

    I realized I skipped one of the parameters inside the wp_enqueue_script function, so that my intended $in_footer parameter was interpreted as the $ver parameter.

    My solution was this:
    wp_enqueue_script( 'production.min.js', get_template_directory_uri() . '/js/production.min.js', array('jquery'), null, true );

    …to add “null” as the $ver parameter before the last “true” value.

  3. Justin Tadlock

    Yep, you have to include the `$in_footer` parameter there to load it in the footer.

    Also, another related thing: if for some reason, you have to enqueue a script later in the page, WP will automatically add it to the footer. This is typically something done by plugins though rather than themes.