How to use wp_enqueue_script() in WordPress Theme Footer

When running a Yslow test on your WordPress site, you’ll notice one of the performance score about putting your Javascript at bottom. Why should javascript be put in footer you might ask? According to yahoo developer, it is one of best practice rule for speeding up your website.

WordPress wp_enqueue_script() usage
[php]<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?> [/php]

Themes developer commonly use WordPress wp_enqueue_script() in their theme’s functions like this
[php]wp_enqueue_script(‘html5shim’, ‘//’, array(‘jquery’), ‘1.1’ );[/php]
but this code always put the scripts before end </head> and not in the footer.

In this post, you’ll learn how to use wp_enqueue_script() in WordPress Footer. Just edit your current wp_enqueue_script() like above code to new code like this:
[php]wp_enqueue_script(‘html5shim’, ‘//’, false, ‘1.1’, true );[/php]
as you can see the code are much different than the first one. i removed the array(‘jquery’) handler and set $in_footer to ‘true’.

With this edits, your javascript should be properly enqueue in your WordPress theme footer with the exception of WordPress default jQuery.

Scroll to Top