Home » WordPress Tutorials » You are reading »

How to use wp_enqueue_script() in WordPress Theme Footer

js-wp-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 wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?> 

Themes developer commonly use WordPress wp_enqueue_script() in their theme’s functions like this

wp_enqueue_script('html5shim', '//html5shiv.googlecode.com/svn/trunk/html5.js', array('jquery'), '1.1' );

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:

wp_enqueue_script('html5shim', '//html5shiv.googlecode.com/svn/trunk/html5.js', false, '1.1', true );

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.

Related Topics:

WordPress Tutorials
Building Your Website with WordPress? Learn How to Optimize it
WordPress Tutorials
How to Detect Mobile or Tablet Condition in WordPress
WordPress Tutorials
Designing and Protecting Your WordPress Site is Easier Than You Think
WordPress Tutorials
The Ultimate SEO Tips For Your WordPress Blog
How to use wp_enqueue_script() in WordPress Theme Footerhttp://cdn.dezzain.com/1/2013/07/js-wp-footer.jpghttp://cdn.dezzain.com/1/2013/07/js-wp-footer-150x150.jpgRichie KS WordPress Tutorialswordpress codingLearn How to use wp_enqueue_script() in WordPress Theme Footer. Putting Javascipt in HTML code footer is one of best practice rule for speeding up your website. DEZZAIN.COM
Enjoy This Article?, Follow us or Share it smiley
viral and buzz WordPress theme

1 Comment Already

  1. This is a very good call. I’ve worked on clients sites where it has just been added into the header directly, then issues come up and then it snowballs! Thanks for the share! 🙂

    Public CommentUserThis is a very good call. I've worked on clients sites where it has just been added into the header directly, then issues come up and then it snowballs! Thanks for the share! :)

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


You can wrap php, js or style css code with [PHP]..your code...[/PHP]