Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Enqueue jQuery for front of site in a plugin

So I know how to load jQuery on the front end of a site, but my problem is what if its already been loaded by the theme or another plugin?

I am asking because I have seen in the past with sites I have inherited that jQuery has been loaded more than once and it caused conflicts. I had to go into the plugin and remove it but when I update the plugins I have to go back in an remove it again.

So my question is how can I find out if there is jQuery already loaded?

2 Answers

Kevin Granger
Kevin Granger
20,332 Points

Hi JP,

"Say you were going to do an include on a whole bunch of pages, and inside of that include you wanted to do some jQuery specific stuff. That page may or may not already have jQuery loaded. If it already does, you don't want to load it again, but if not, you do. This works for that."

http://css-tricks.com/snippets/jquery/load-jquery-only-if-not-present/

Hope it will help.

Hi Kevin,

Many thanks for this. I never thought to look for a JS solution for this. I'm going to add this to my plugin.

I was actually trying to find a solution within my WordPress plugin PHP, I would really like to see if there is a solution for use in my plugin too so will still leave the question open.