0

I am trying to place Javascript within the wp_footer (this is based on a previous question I asked here).

I would like for this Javascript to appear on the wp_footer of several templates but when I load it into functions.php here's what happens:

  1. [GOOD] The Javascript is correctly placed where it is meant to be, but;
  2. [BAD] The same Javascript is then oddly placed OUTSIDE of the closing < /html > tag which is odd.

Thanks for all direction.

 function jsdirectoryfilter() {
   if ( is_page_template( array('page-directory-2013.php','page-directory-2014.php','page-directory-2015.php','page-directory-2016.php','page-directory-2017.php','page-directory-2018.php'))){
    ?>
    <script>var options={valueNames:["name","location","category"]},userList=new List("users",options);</script>
    <?php
  }
}
add_action( 'wp_footer', 'jsdirectoryfilter' );
6
  • Are you sure you don't have another instance of wp_footer() in some of your templates?
    – Jack Johansson
    Aug 10 '17 at 10:18
  • At the bottom of every template are the usual <?php get_footer(); ?> + <?php wp_footer(); ?> tags.... - is that what you meant?
    – Henry
    Aug 10 '17 at 10:21
  • Yes that's what I mean. You should only have one of them in your template files. get_footer() should be in your template, and wp_footer() should be in your footer.php, before the closing </body> tag.
    – Jack Johansson
    Aug 10 '17 at 10:23
  • Ah i see....i think that get_footer is the hook to read wp_footer for the template files - is that correct? Should ONLY template files have the get_footer? I need to read up on it!
    – Henry
    Aug 10 '17 at 10:26
  • Yes, if I see other themes (even the official WordPress ones) I can see that there is only get_footer
    – Henry
    Aug 10 '17 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.