I read the Codex and a few blog posts about using jQuery in WordPress, and its very frustrating. I've got as far as loading jQuery in functions.php
file, but all of the guides out there are crappy because they assume you already have a ton of WordPress experience. For instance, they say that now that I'm loading jQuery through the functions.php
file, now all I have to do is load my jQuery.
How exactly do I do this? What files, specifically, do I add code to? How exactly do I add it for a single WordPress page?
There are many tutorials and answers here how to add your script to be included in the page. But what I couldn't find is how to structure that code so it will work properly. This is due the $ being not used in this form of JQuery.
So here is my code and you can use that as a template.
**#Method 1:**Try to put your jquery code in a separate js file.
Now register that script in functions.php file.
Now you are done.
Registering script in functions has it benefits as it comes in
<head>
section when page loads thus it is a part of header.php always. So you don't have to repeat your code each time you write a new html content.#Method 2: put the script code inside the page body under
<script>
tag. Then you don't have to register it in functions.