• Hi everybody,

    I have recently noticed that all my JavaScript scripts went into the bottom of the html. First I though it was because of minify plugin. But no, it is not releated at all. I mean I don’t mind but I can’t google any trace of this change at all. So what happend and when?

    Charlie

Viewing 5 replies - 1 through 5 (of 5 total)
  • How are you enqueuing these scripts?

    Thread Starter Charlie333

    (@charlie333)

    That’s the thing. I do like this – in the top of my template file:

    function _head(){
    
     wp_enqueue_style('bootstrap', '//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css');
    	wp_enqueue_script('bootstrap', '//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js', array('jquery'));
    
      wp_enqueue_script( 'jquery' );
    
    ?>
    
    <script>
    var global_variable={<?php /* PHP code for JSON generation */ ?>};
    jQuery().ready(/* some important function also generated in PHP*/);
    </script>
    <style>
    
    // some css
    
    </style>
    
    <?php
    
    }
    add_action('wp_head', '_head' );

    Everything goes into wp_head, but scripts goes into wp_footer. So the variable and jQuery call will go wrong as it will stay in the head – and it will go before jQuery and other scripts.

    That’s not how you enqueue an external script. Have you reviewed wp_enqueue_script()?

    Thread Starter Charlie333

    (@charlie333)

    One more time – ANY script I DO register with wp_enqueue_script() by action wp_head is rendered in html in wp_footer. My expectations are: script in wp_head are in wp_head, scripts in wp_footer are in wp_footer. But in WordPress 3.9 every script is magically moved into footer. Apart of jQuery – WordPress keeps rendering it in wp_head. My question is – if it has been changed in 3.9 – why there is no trace in codex or anywhere else? Or maybe somehow I have hacked three different WordPress instalations?

    OK – let’s try again…

    what file is the code snippet from above?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Why my scipts are in the bottom of html?’ is closed to new replies.