WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] Enqueuing scripts in footer does not working with WordPress 3.6? (8 posts)

  1. jtost
    Member
    Posted 1 year ago #

    Hi!

    I have a strange problem since I last updated WordPress to 3.6: My enqueuing method isn't able to place my scripts in the footer.

    Here's my code (that worked good with WordPress 3.5 and previous versions):

    function my_scripts_method() {
        wp_enqueue_script('flexslider', get_template_directory_uri().'/js/jquery.flexslider-min.js', array('jquery'), null, true);
        wp_enqueue_script('waypoints', get_template_directory_uri().'/js/waypoints.min.js', array('jquery'), null, true);
    
        // My functions file
        wp_enqueue_script('theme_functions', get_template_directory_uri().'/js/functions.js', array('jquery', 'flexslider', 'waypoints'), null, true);
    }
    add_action( 'wp_enqueue_scripts', 'my_scripts_method', 20 );

    Anyone has an idea?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Try reviewing http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    $in_footer
    (boolean) (optional) Normally, scripts are placed in <head> of the HTML document. If this parameter is true, the script is placed before the </body> end tag. This requires the theme to have the wp_footer() template tag in the appropriate place.

    Default: false

  3. jtost
    Member
    Posted 1 year ago #

    Hi esmi, thanks for your reply.

    I reviewed the documentation but didn't find the reason. I always use this method to place the scripts in the footer.

    But since I last updated to WP version 3.6 they aren't placed at all! Neither in the footer or in the <head>. They aren't enqueued at all... It's strange.

    Has anyone the same problem?

  4. jtost
    Member
    Posted 1 year ago #

    For example, if I use it (don't set $in_footer)

    function my_scripts_method() {
        wp_enqueue_script('flexslider', get_template_directory_uri().'/js/jquery.flexslider-min.js', array('jquery'));
        wp_enqueue_script('waypoints', get_template_directory_uri().'/js/waypoints.min.js', array('jquery'));
    
        // My functions file
        wp_enqueue_script('theme_functions', get_template_directory_uri().'/js/functions.js', array('jquery', 'flexslider', 'waypoints'));
    }
    add_action( 'wp_enqueue_scripts', 'my_scripts_method', 20 );

    The scripts are enqueued und placed in the <head>.

    But if I use it (setting $in_footer=true):

    function my_scripts_method() {
        wp_enqueue_script('flexslider', get_template_directory_uri().'/js/jquery.flexslider-min.js', array('jquery'), null, true);
        wp_enqueue_script('waypoints', get_template_directory_uri().'/js/waypoints.min.js', array('jquery'), null, true);
    
        // My functions file
        wp_enqueue_script('theme_functions', get_template_directory_uri().'/js/functions.js', array('jquery', 'flexslider', 'waypoints'), null, true);
    }
    add_action( 'wp_enqueue_scripts', 'my_scripts_method', 20 );

    They aren't placed at all, neither before the </body> end tag or in the <head>.

    I'm using wp_footer() right before </body>

  5. jtost
    Member
    Posted 1 year ago #

    I checked if wp_footer() is working with this hook:

    function your_function() {
        echo '<p>This is inserted at the bottom</p>';
    }
    add_action('wp_footer', 'your_function', 100);

    And it seems that it isn't called... I use it in my footer.php file right before the </body> closing tag.

    Anyone has experienced the same problem? For previous versions of WordPress (<3.6) the code worked fine.

    Thanks for your time.

  6. jtost
    Member
    Posted 1 year ago #

    I found the problem.

    One plugin had a PHP error and the footer wasn't attached at all...

    :-)

  7. MaTaX91
    Member
    Posted 4 months ago #

    How did you track down the error?

  8. virijoyfl
    Member
    Posted 4 months ago #

    I'm having the same issue and am wondering the same thing as above. Any more explanation about what the problem was, @jtost?

Topic Closed

This topic has been closed to new replies.

About this Topic