WordPress hardly needs any introduction; it is easily among the most widely used and powerful blogging platforms of the world. On similar lines, JQuery is another success story, and is regarded as the most power packed JacaScript framework across the tech globe.
JQuery, when used in conjugation with WordPress, gives you websites with great sliders, gallery options and menus. Obviously, you can do wonders when you combine these two juggernauts. However, there are some tips and tricks that you’d do well to remember so that you are never left high and dry fending against JQuery conflicts.
WordPress uses JQuery, and this means that there is no need for you to add JQuery script to it. In order to add the power of JQuery in your theme, all you need to do is to add the following little coding statement in the theme.
<?php wp_enqueue_script(“jquery”); ?>
When you have the above coding fragment in the header.php file, then JQuery gets added to your WordPress theme. In order to ensure that there are no inadvertent conflicts interrupting the smooth flow of your website, you’ll need to add the following coding block.
// Code that uses other library’s $ can follow here.
This method of using code to prevent conflicts works particularly well when complemented by the .ready() technique. The later has the capability to make an alias of the JQuery object. We can use $ in callback passed to the .ready(). Here’s another coding fragmant that can help you avoid JQuery conflicts; this one is generally preferred by expert WordPress users and JQuery coding experts.
var j = jQuery.noConflict();
// Do something with jQuery
// Do something with another library’s $()
$(“content”).style.display = ‘none’;
There’s another very easy and smart method that you can rely upon to get past all JQuery conflicts, and that is by using JQuery more than once for each JQuery plugin you use.