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.
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?
_doing_it_wrong()
, and ask for a fix.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
$
orjQuery
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)