Tips For Using Jquery In Wordpress

In the past, I've used quite a few themes as well as plug-ins that have used wordpress and query, so I thought I'll share a few tips with everyone such that you do not make the same mistakes which I did in the beginning and even so that you could make your work more efficient.



First off: guarantee you don't use the wp_enqueue_script() tag in your html page. A lot of people make this mistake, but realize that when you do this it normally causes more problems than you can or would ever want. Rather, you would like to make sure you use the Jquery code below:

function my_init()
if (!is_admin())
wp_enqueue_script('jquery');
add_action('init', 'my_init');

Obviously you can replace my_init with something a little more memorable. Just ensure its something unique so that you don't get things confused.

 Secondly: ensure you load your JQuery from the Google Ajax Library. Since Wordpress already includes a call to which incorporates Jquery, calling the code; wp_enqueue_script('jquery'); would allow it to automatically load into the file.

Third: make sure you load Jquery in the footer of the coding. If you use the first two tips I mentioned, then Jquery would automatically be added to the head of your HTML page. However, if you'll like it added to the bottom instead, you would have to use the $in_footer parameter. The modified code would look something like this:

function my_init()
if (!is_admin()) wp_deregister_script('jquery');
// load the local copy of jQuery in the footer
wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', false, '1.3.2', true);
// or load the Google API copy in the footer
//wp_register_script('jquery', '<http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js>', false, '1.3.2', true);
wp_enqueue_script('jquery');
add_action('init', 'my_init');

Lastly: ensure you load Jquery as a dependent script. If you use the wp_enqueue_script() function property, this will automatically allow wordpress to manage the order of your script tags. A nice addition to have!

If you are still learning programming codes as well as you need extra help, you can find a lot of sites online that offer free tips and tricks such as ASP tutorial, ASP.NET tutorial, and Jquery tutorial. Most of these tutorials would be text or image based. You could find a few that are videos, but with something like this, it seems text is the best way to go. Even if you're semi-educated in the ASP tutorial, ASP.NET tutorial, and Jquery tutorial, but you would want to learn CSS or other codes, you can do this online as well. Its all pretty simple depending on the type of site you look at. If its cheat sheets you are looking for and you want to learn CSS or you want cheats on HTML, CSS or ASP, You could even make use of the websites such as web monkey or even W3Schools to help you.




Thank you Friends keep visiting my blog for more tips and tricks.

0 comments:

Post a Comment