Using jQuery with WordPress

A couple of years ago I started trying to figure out how to use this version of javascript called jQuery. I’d heard a lot about it, and had seen it in action in a few places, and I thought it was really cool. I had little trouble using it on regular HTML pages, but when it came to using it in WordPress, I was stumped.

I am not a programmer, so my learning curve was pretty steep here. Because WordPress works differently than a vanilla HTML page, I had a hard time figuring this part out.

I will cut to the chase here and tell you how I did it, since chances are that if you found this post through a Google search, you didn’t come here to read my life story.

I’ll just say this: the reason I’m making this post is because NO ONE OUT THERE WAS ABLE TO EXPLAIN IN NOOB TERMS HOW TO DO THIS. It was making me crazy. In the end it turned out to be a two-part explanation, but every single tutorial I came across left out either one or the other, likely because they assumed I already knew a bunch of stuff. Well, I didn’t. And chances are, if you’re reading this, neither do you.

So this is for you, my fellow noobs.

To use jQuery in your WordPress site, do the following:

1. Copy the following function and paste it into to your functions.php file (this is called “enqueuing jQuery”):

function insert_jquery(){

2. Call the specific jQuery function you want by putting it between tags on your PHP or HTML page. For example:

// Your jQuery script goes here

That’s it. You can now run jQuery scripts on any WP page in your site.

Now, if you don’t know what these things mean, you need to back up a few steps and master what you’re missing. This is where I fell down several times. For example, after messing with my functions.php page, I would often end up with the White Screen of Death. If not that, then I couldn’t figure out what “Your jQuery script goes here” meant. Yes, I knew it meant to put a script there. But how exactly did I put it there? And what did I do when it didn’t work?

To keep this post short, I’ll stop here, but I intend to write a few more posts targeted at the kind of WordPress user I was (and to a large extent still am): advanced enough to be asking hard questions, but still ignorant enough not to understand the answers.