What do you think?
Fixing jQuery Problems in WordPress Websites
Lots of WordPress plugin developers use jQuery to help you add features to your website. It drives lightboxes, drop-down menus, sliders and forms plus lots of other elements, so what do you do when it breaks or stops working?
jQuery is a very popular language on the web these days. It’s fairly easy to learn and implement on your site and it can add a lot of functionality which makes your site more user-friendly and better looking! You can learn about it here on the jQuery website.
If you are using it (maybe to show elements hidden with your CSS) or have installed plugins that rely on it, there may be issues with multiple instances of it being loaded. You can get around this, by adding some code to your theme‘s functions.php file, to ‘enqueue’ jQuery:
// Load jQuery
if ( !is_admin() ) {
wp_deregister_script(‘jquery’);
wp_register_script(‘jquery’, (“//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”), false);
wp_enqueue_script(‘jquery’);
}
Here, we first ‘deregister’ jQuery to ensure that multiple copies aren’t already firing, then we register or load it using the Google jQuery script library. This is a good idea because lots of other sites seem to use this method and your visitors may already have it in their browser’s cache. Finally, we add jQuery to our queue so it is ready when needed.
Two other points that are worth noting:
- Keep your Google library version number as current as possible. This reduces possible problems as changes are made to any plugins you are using.
- When using your own jQuery script in a WordPress site, make sure to use ‘jQuery’ in full rather than the abbreviated ‘$’. Again, this limits conflicts. For example:
jQuery(document).ready(function(){
});
other page
It's good to talk!