Support » Plugins » How to use jquery in wordpress?

  • Hi,
    I am trying to use jquery in my wordpress theme but it is not working.
    Similar data written in an html file works but for the wordpress that thing is not working.
    Please help me out.
    Thanx in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • From WP2.5 (i think) jQuery it’s included, u have some ways to call and inject jQuery in your theme:
    Directly or using the WordPress functions (recommended).

    1. Directly, it’s the same way wich u has mentioned (<script src=”…).
    2. Using wordpress, more elegant:
    See wp_enqueue_script() and wp_register_script().

    I hope this will be useful. 😉

    and rather than the shortcut $ you should use jQuery(“#foo”)

    Can’t get jQuery localScroll to work (so there is an animation between local anchor links on the same page):

    <?php wp_enqueue_script( 'scrollTo', 'wp-content/themes/abletonartists/js/jquery.scrollTo-min.js', array( 'jquery' ) ); ?>
    	<?php wp_enqueue_script( 'localScroll', 'wp-content/themes/abletonartists/js/jquery.localscroll-min.js', array( 'jquery' ) ); ?>
    	<script type="text/javascript">
    		$(document).ready(function() {

    @doodlebug – any error messages from Firebug?

    I’ve since done it direct like this and it works…
    <script src="<?php bloginfo('stylesheet_directory'); ?>/js/jquery-1.2.6.min.js" type="text/javascript"></script>

    I know this isn’t the right way to do it – how can I use the in-built jQuery properly? All the documentation/writings concentrate on the perspective of plugin writers, not theme authors!

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Your enqueue bits are fine, but make sure those calls happen BEFORE the wp_head action. This can be in a plugin or anywhere else. For a theme, puitting them in functions.php would work fine if you put them in a function hooked to the template_redirect action (to prevent them from also enqueuing in the admin screens).

    function my_theme_enqueue() {
    ... etc, all your enqueues go here ...

    Your actual script output would need to be elsewhere. In the relevant template, I expect.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to use jquery in wordpress?’ is closed to new replies.