Using jQuery in WordPress
-
I’m looking for some help on how to use jQuery in WordPress. I have been googling for hours without success and I’d really appreciate some help.
I’m trying to follow the steps in this tutorial. I’m fine with the HTML and CSS bit, but can’t understand what to do with the jQuery.
From what I’ve read I believe I have to paste create a file called “accordion.js” with the jQuery script inside of it and upload it onto my server. I’ve done this and put it in the folder where I can see my theme (minimatica.js) file.
Then in my themefunctions.php I’ve pasted the following line near where I can see other scripts being called:
wp_register_script( 'accordion', get_template_directory_uri() . '/scripts/accordion.js', array( 'jquery' ), '1.3.16' );
I wasn’t sure what the values for the penultimate and last part of that string should be. I opted for ( ‘jquery’ ), ‘1.3.16’ ); because that’s what a line of code above did.
Finally I know that I need to queue up jQuery in my header.php file.
I’ve read that before the <head> section I need to put:
<?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?>
And then after <?php wp_head(); ?>:
<script type="text/javascript" src="<?php bloginfo("template_url"); ?>/js/yourScript.js"></script>
I’m not following what words should be going where. I can see that /js/yourscript.js should probably be changed to the path I’ve put accordion.js, in my case. However should I be replacing anything else in there to get it to work?
I’d really really love some help. A similar post on the forum had a response saying “if you can’t understand how this works you shouldn’t be doing it” which lets face it, is a really rubbish thing to say to people who are learning. I’ve really tried to find a tutorial. website here if you want to see how far I’ve got with it
- The topic ‘Using jQuery in WordPress’ is closed to new replies.