Have you ever been building a theme, creating a plugin, or modifying a child theme and discovered a jQuery conflict? Well, I have. And usually it’s not a big deal. I’ve been working on a site though that was having a lot of issues. It was already needing to load 2 different versions of jQuery to work (an older version for some scrolling work, and the most recent for Bootstrap). While it all worked fine in the initial html build, once it started to be converted to a WordPress theme there were serious problems. It turns out that WordPress comes preloaded with jQuery. You don’t add it to your theme functions.php file. It’s just there.

But the problem is that now I was suddenly loading 3 versions of jQuery! This is NOT GOOD!

So here’s the code you need in order to disable the native WP jQuery (thank you CSS Tricks for this solution)!

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
}

Replace the “://ajax…” with the path to whichever version you’re using. That’s it!

thePixelPixie.com - WordPress boutique

Subscribe and receive my FREE eBook


4 MISTAKES You’re Making on Your Website that are Costing You MONEY!

  • This field is for validation purposes and should be left unchanged.

The Author

Save

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ready to chat about how ThePixelPixie can help?