Adding JavaScript Libraries to WordPress

WordPress includes a number of JavaScript libraries because it uses those libraries in the administration screens. They’re available for you to use in your themes and plugins as well. The libraries include jQueryPrototypeScriptaculous, and SWFUpload. See the wp_enqueue_script Codex page for a complete list of the scripts available, along with their handles.

This code, added to your plugin or theme functions file, will add jQuery and its UI library:


<!--?php
//Including jQuery
function scl_add_jquery() {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
}
add_action('wp_head', 'scl_add_jquery');
?>

Using jQuery in WordPress is a bit tricky. Most jQuery scripts rely on a dollar sign function. For example, $("div.main").addClass("wide"); would add the wide class to a div that already had the main class. However, several other libraries, including Prototype, use this same convention. Because WordPress also uses Prototype, the jQuery library is loaded in “no conflict” mode.

You have two options. You can use ‘jQuery’ in place of the dollar sign function (‘$’) throughout your script, or you can wrap your script in an extra function.

 
// using jQuery without a wrapper: replace $() with jQuery()
jQuery("div.main").addClass("wide");

jQuery(document).ready(function($) {
// $() will work inside this function; otherwise use jQuery()
$("div.main").addClass("wide");
});

What libraries are you using? Let me know some intresting JavaScripts libraries you have come across.

WordCamp Mumbai 2012

WCMumbai 2012 was my first WordCamp. It was organised by some of the students from a local college. Until now, I had not expereinced any WordCamp. This was a exicting experience. I met some really intresting people around the globle.

I learnt some intresting things I had not explored until now. Got some lessons on Theme development from Philip Moore. I also had a discussion regarding _s and other started themes with Philip after the talk.

I also learnt using AWS for hosting WordPress from Puneet Sahalot, his blog  at https://iampuneet.com/ is pretty intresting.

There were also some I already knew, like Prajot Mainkar, who is more involved with the Google Meetups. I knew him from there. He talked about HTML 5 and Android.

I also meet people from IndiBlogger.in, I did not know blogger have such massive community until now.

Made some new friends Ashish Kamble, Lionel Gracias, Mitesh Sanghvi and Shashank Chinchli too.

Mitesh is known for his exceptional knowledge regarding SEO and digital marketing.

Over all it was a nice experience, I loved it.