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() {
$.localScroll({
duration:1600
});
});
</script>
@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!
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() {
wp_enqueue_script('whatever'...
... etc, all your enqueues go here ...
}
add_action('template_redirect','my_theme_enqueue');
Your actual script output would need to be elsewhere. In the relevant template, I expect.