1

I am currently working on the footer.php file. I am just wondering where I should place the wp_footer(); in relation to the <footer> elements. Which of the following would be correct?

Method A:

<footer>            
    <h1>Title Text</h1>
    <p>Some text</p>
    <?php wp_footer(); ?>
</footer>   
</body>
</html>

Method B

<footer>            
    <h1>Title Text</h1>
    <p>Some text</p>
</footer>   
    <?php wp_footer(); ?>
</body>
</html>

I checked WordPress' Codex but could not find a solution. I did not notice any aesthetic difference to the web page. So maybe it is a personal preference?

2

wp_footer() loads enqueued JS files, etc.

Place it just before the closing tag like in method B.

  • Great. Thank you for your answer. I validated the HTML of both Methods and both 'passed'. Would I be right in thinking, the reason for placing wp_footer() just before the closing body tag, is to defer the loading of JS files etc, as to help the page load quicker? – Craig Oct 9 '17 at 1:58
  • I apologise, I should have given a more in depth answer. Both versions are valid HTML but I think it's good practice to place just before the closing tag because it avoids conflicts later on and with any plugins. The JS should be the last thing to load in case anything in the footer has JS dependencies to. – lukgoh Oct 9 '17 at 7:53

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.