Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress Genesis Framework Foundations How to Install Genesis and a Child Theme Review a Post Editor Screen

What is the best method for loading JavaScript files in a Genesis theme?

In the video, he shows that there is an option to add a JavaScript file to specific pages, although it loads it them the <head>.

Would it be better to use the wp_enqueue_script() function within a conditional statement to only load the script on the specific page(s)? I know this would give you the option to load the scripts at the end of the body.

3 Answers

Jeremy Castanza
Jeremy Castanza
12,081 Points

Hi Lance, no problem.

The wp_enqueue_script hook also comes with an option to load an external JavaScript at the top of a page or at the bottom near the body close tag.

For more information on this option, refer to the Codex: https://developer.wordpress.org/reference/functions/wp_enqueue_script/

Happy Coding! Jeremy

Jeremy, Ya know I never knew that option was available . I see it now that I look at the Codex page. Awesome!!!

$in_footer (bool) (Optional) Whether to enqueue the script before </body> instead of in the <head>. Default 'false'. Default value: false

Jeremy Castanza
Jeremy Castanza
12,081 Points

I can't speak for the Genesis framework. However, in terms of WordPress, enquiring is the preferred method rather than including in a page template. I think it boils down to separation of design and functionality. Which method you choose may also come down to page loading times.

This is a very good question. As we get "DINGED" for loading them in the header on the front page when looking at Google page speeds. I know other frameworks load them at the bottom of the page before the </body> tag. I am working on a site now where I am making the front page "GOOGLE happy" and site owner happy then going from there with the rest of the design. Thanks Jeremy for the reply as I am pretty new to the wordpress world and appreciate any Wordpress insight.