Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Theme developers like to deregister wordpress jquery and load jquery from google instead.

I've been told it is for speed and I agree.

This usually is not a problem for me since I always use jQuery instead of $.

But I do see some plugins try to use $, well, it generates javascript error and also makes my plugin not working. As a result, clients blame on innocent me.

Sometimes my js code depends on the version of wordpress jquery but theme developers tend to load a specific version from google.

Even though the theme is updated, they may not update the jquery version, not to mention an old theme.

What should I do in such situations?

Actually, I'm thinking about, maybe I should use Zepto.js instead and include it in my js code.

p.s. good news, wordpress 3.6 doesn't allow deregister jquery in its backend.

share|improve this question
    
Did not know that about wp 3.6 :). For interested devs, here's the trac ticket core.trac.wordpress.org/ticket/22896 –  Stephen Harris Aug 5 '13 at 8:21

2 Answers 2

up vote 5 down vote accepted

Any Theme developer that dequeues core-bundled jQuery in order to enqueue some other version - any other version, bundled, CDN, etc. - is _doing_it_wrong(), period. Core, active Theme, and active Plugins all rely on a known version of jQuery being available.

What to do about it?

  1. Tell the Theme developer that he's _doing_it_wrong(), and ask for a fix.
  2. Tell your Plugin users to use a Theme hosted in the official WordPress Theme directory, since every Theme hosted there is prohibited from dequeueing core-bundled jQuery
  3. Instruct your Plugin users how to override the Theme's jQuery override, via a site functionality Plugin that dequeues the Theme's custom jQuery, and re-enqueues core-bundled jQuery
  4. Instruct your Plugin users how to patch the Theme's incorrect jQuery implementation, by adding no-conflict wrappers
share|improve this answer
    
no offense. It's not practical. Maybe I should try to convince wordpress dev core team? hehe –  Jesse Aug 5 '13 at 4:34
    
@Jesse - In my experience users accept its something the theme developer 'doing something wrong'. I typically tell them how to fix it, but also advise that they contact the theme developer. –  Stephen Harris Aug 5 '13 at 8:17
1  
@StephenHarris I'm hired by affiliaters and they sell the plugin to newbies who are very scared to touch the code. So, I have to fix it one by one and yes, I should have let users, rather than me, report to theme developer. My report was ignored by a "big-time" affiliate theme and didn't thought of reporting issue ever since... –  Jesse Aug 5 '13 at 9:33
    
@Jesse convince the WordPress core dev team... of what, exactly? :) If your users don't want to touch code, just write the Theme fixes directly into the Plugin. Then, you can just update the Plugin each time you find a new Theme that you need to "fix". –  Chip Bennett Aug 5 '13 at 14:03
    
@ChipBennett given that theme developers are _doing_it_wrong() and wp 3.6 also disallows deregistering critical third party scripts in backend, I think there is a chance that can talk them down to do the same thing in the front-end too. maybe I'm just dreaming. :] –  Jesse Aug 5 '13 at 14:12

I know this is a bit old, but seems to come up a lot.

I am sorry to say mate, but you and the wordpress team are the ones who are _doing_it_wrong() (I'm only talking about the front-end part of things, not the admin panel)

First of all, it is not safe to always use the latest jQuery cause things can change and people don't always (read: very rarely) update their code when a new version comes out.

Second - whether you use $ or jQuery shouldn't matter. Just stop using global variables altogether and write your js code inside a closure. Don't view $ as a bad practice because wordpress team says so, they are not the best source when it comes to good practices anyways.

And finally loading js should be done in the end of the DOM, not in the <head> section (another bad practice from wp team)

share|improve this answer
    
about the Second. the problem is A loads jquery from code.google.com and didn't call jQuery.noConflict(), resulting in javascript error generated by B who directly use '$'. Because of this javascript error, my js code can't be working and users complaint about my plugin not working. How to solve this problem? Hopefully, this makes my question more clear to you. –  Jesse Mar 10 at 10:56
    
@Jesse well that's just false. Unless you have all your js in the same file with the offending plugin's js - an error happening in a different js file will not affect yours. You are wrong on that one. –  YemSalat Mar 13 at 1:11
    
thanks for clarifying. You are right. I'm trying to reproduce the same error but I can't make it maybe it's because I'm out of wordpress development for a while. But, I'm pretty sure about that. I had to deal with the jquery conflict a few times every week. Gotta get rid of wp_deregister_script('jquery'); wp_register_script... from theme so that the conflicted plugin can be working which makes my plugin working too. @yemsalat –  Jesse Mar 13 at 8:20

Your Answer

 
discard

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.