WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At the start of a typical plugin which uses jquery I have something like the following

wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', false, '1.3.2');

Which as I understand it deregisters and re-enqueues jquery ( from google in this example but that's irrelevant here )

My question is this: is there not some way of checking to see whether the library is already enqueued ( by another plugin or the theme) to save needless deregister/register and enqueue ( or is this not very expensive in reality )

share|improve this question
up vote 3 down vote accepted

Enqueues are not piling up if done multiple times (that is kinda the point of having a queue).

As for registration - frankly it shouldn't be done by most (public) plugins. WordPress comes with jQuery to use and when that copy is re-registered to something else - it affects all plugin and theme code that depends on it.

If it's private code - just do registration once somewhere, no need to duplicate it.

share|improve this answer
Sorry I dont quite understand. Are you talking about getting jquery from Google? I didnt think there was in effect any real difference between the code above and just wp_enqueue_script('jquery'); I thought that was a different argument with it's own pros and cons .... can i just clarify are you saying that even if wp_enqueue_script('jquery'); is called 20 times in the site it makes no notable difference ( becauase it's an enqueue) – byronyasgur Sep 14 '11 at 18:49
@byronyasgur there is possible difference in jQuery version and WP loads its jQuery in noConflict mode, while Google does not. even if wp_enqueue_script('jquery'); is called 20 times in the site it makes no notable difference ( becauase it's an enqueue) - yes. – Rarst Sep 14 '11 at 20:00
I think I see your point about the google version. In fact just before I read this it was beginning to dawn on me that the WP version updates with WP; wheras the google version needs manual updating ( of the line of code ). That on it's own would convince me to use the built in WP version, but the noConflict issue nails it. Thanks – byronyasgur Sep 14 '11 at 20:54
*Click* !! ... all (eg 20) the enqueues sum up to just one enqueue - then if that script has been enqueued it is printed with print_scripts .. am I right ? – byronyasgur Sep 14 '11 at 20:59
@byronyasgur yep. Enqueue is declaration of which scripts need to be loaded, then print sorts out all requests and deals with echoing required scripts in required order. – Rarst Sep 14 '11 at 21:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.