• Resolved jtost

    (@jtost)


    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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Try reviewing https://codex.www.ads-software.com/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

    Thread Starter jtost

    (@jtost)

    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?

    Thread Starter jtost

    (@jtost)

    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>

    Thread Starter jtost

    (@jtost)

    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.

    Thread Starter jtost

    (@jtost)

    I found the problem.

    One plugin had a PHP error and the footer wasn’t attached at all…

    ??

    How did you track down the error?

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Enqueuing scripts in footer does not working with WordPress 3.6?’ is closed to new replies.