Select Page

Use one of the following methods to enqueue jQuery in your WordPress theme.

The Quick and Easy Way

This is the way that I usually enqueue jQuery in my WordPress themes. In your themes header.php file, hopefully you’re doing this in a child theme, you’re going to want to add the following before [su_highlight]wp_head();[/su_highlight]

This is originally from: http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/

You could also use google:

Add this to you funtions.php file to download jQuery from googleapis:

This is originally from: http://css-tricks.com/snippets/wordpress/include-jquery-in-wordpress-theme/

But a comment from Carl Hancock in the same post explains why you should usually avoid this method.

ATTENTION WORDPRESS DEVELOPERS:

Do the WordPress community a huge favor and NEVER implement jQuery this way in a theme you will be releasing to the public. Be it a commercial theme or a free theme that you plan on making publicly available.

I would suggest that you ONLY implement jQuery this way on sites you yourself are running and managing AND sites that you will be making sure are always running the latest version of jQuery.

If you are releasing a theme to the public (commercial or free) ALWAYS load jQuery simply by using the wp_enqueue_script(‘jquery’) call and NEVER deregister the built in jQuery and call it from an external source.

WordPress Plugins developed using best practices enqueue jQuery via wp_enqueue_script(‘jquery’) and they expect that to load the version of jQuery that the current version of WordPress is using.

If you have deregistered the built in jQuery call, and registered a call to an old version of jQuery on Google’s servers… you are asking for problems and headaches down the road.

Why? Easy. You are changing the global WordPress environment for all other plugins and WordPress itself by doing this.

If a plugin is expecting jQuery v1.7.1 because that is what is built into WordPress v3.3 and your theme comes along and it has reregistered jQuery and has registered jQuery v1.2.1 from Google’s servers? Shit’s going to break because you may have plugins that are expecting jQuery v1.7.1 and instead your theme is loading jQuery v1.2.1.

WordPress comes with jQuery. It is updated every release. Do the community a favor and don’t change it unless you know what you are doing and you AREN’T releasing the theme to the public.

Theme developers implementing jQuery this way cause countless hours of support for plugin developers and their users when they don’t know what they are doing.

Implementing this is only appropriate on your own site. Loading jQuery should never be done this way in a theme that is being released to the public.

If you want to use jQuery in a plugin you will want to read how to do that here:

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

css.php