Jquery is one of the topmost javascript libraries now using with wordpress. Jquery is having a huge number of plugins which will make our blog amazing look and feel.
For using Jquery with Wordpress we don’t need to include it in our theme folder.
We can use the following code for adding the jquery support to the Wordpress blog.
function jquery_init() {
if (!is_admin()) {
wp_enqueue_script('jquery');
}
}
add_action('init', 'jquery_init');
For plugin development, add the code in your plugin file, otherwise, add this code to your theme’s functions.php file. The is_admin() check is to prevent script queuing on your admin pages.
If you want to load jQuery from the Google AJAX Library, you can use the following code.
function jquery_init() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', false, '1.3.2');
wp_enqueue_script('jquery');
}
}
add_action('init', 'jquery_init');
There are a number of advantageous why you would want to use the Google AJAX Library to load jQuery, but remember, Google has been down before, so be ready to comment out the first two lines if necessary.
February 10th, 2010 