December 10

Using jQuery with WordPress

This is going to be a short post but an important one nonetheless.

Firstly, you may want to know that WordPress 2.2 “switched to jQuery for core JS, which is lighter and faster” (WordPress.org). In order, to include jQuery in your pages, simply add the following HTML to the <head> of your document:

<script type=”text/javascript” src=”/wp-includes/js/jquery/jquery.js”></script>

Secondly, you want to make sure that all your declarations starting with the “$” symbol are replaced by “jQuery”. It has to do with other JavaScript libraries coexisting in WordPress. In other words:

Don’t do this:

$(”p”).css(”color”, “#fff”);

Do this:

jQuery(”p”).css(”color”, “#fff”);

Hopefully this helps those of you out there trying to incorporate jQuery into your WordPress pages. Comments and/or question are always welcome.

stumble upon icon

Leave Your Thoughts