22 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item that was trending
+4 more
Yatek
says

Hello WP plugin developers,

How do you deal with jQuery?

Normally any plugin / theme have to check if jQuery was already included and include it’s own “jquery.js” only if newer version is required ( but first call wp_deregister_script(‘jquery’); )

In real life there are too many poorly written plugins / themes which doesn’t do any checks and just throw in their own “jquery.js” which causes conflicts.

So what is the best way to deal with that when you create a WP plugin which uses 10 jQuery plugins which depend on jQuery, let’s say 1.7.2.

I know about $my_jQuery = jQuery.noConflict(); method but it isn’t too useful when you have 10 jQuery 3rd party plugins used by your WP plugin. Each is wrapped into function($) ... (jQuery) so they won’t work with $my_jQuery. I don’t want to edit all 3rd party plugins changing them to function($) ... ($my_jQuery) I hope you understand this.

1560 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+2 more
OriginalEXE
says

If a client is using fault plugins, that is their fault and not yours. I never include jQuery as WordPress loads it by default. If for some reason things don’t work, then you know it’s not your fault but of 3rd party.

You can’t (and shouldn’t) fix others mistakes.

376 posts
  • Had an item that was trending
  • Had an item that became a weekly top seller
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
+12 more
RightHere
says

@Yatek it is definitely a bad idea to include your own jQuery or force the use of a specific version. As OriginalEXE says WordPress includes its own jQuery.

This is one of the most common errors we experience with plugins and themes. Whether you want to help your client and fix the error, so your plugin works is up to you!

We do help our customers even though the error is not in our plugin ;)

22 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item that was trending
+4 more
Yatek
says

thanks @OriginalEXE & @RightHere :) Good points you made

1466 posts
  • Had an item that was trending
  • Won a Most Wanted contest
  • Has sold $10,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+8 more
greenline
says
I have the same problem. In my plugin, do I have to include the default jquery loaded by wordpress or not? Like below:
wp_deregister_script('jquery');

Because I know Wordpress includes jquery only from version 3.5….So what about the old wordpress versions? I want to make my plugin campatible with older versions too.

Please if someone knows the correct way the jquery without interfering with theme’s jquery …please let me know.

2279 posts
  • Became a Top 20 Author of the Month
  • Had an item that became a weekly top seller
  • Created a helpful tool/app using the Envato API
  • Created a helpful tool/app for Envato Market users
+15 more
revaxarts
says
I’ve added a filter so peaople can remove the jQuery verison if it’S already there:
wp_register_script('mymail-form', MYMAIL_URI . '/assets/js/form.js', apply_filters('mymail_no_jquery', array('jquery')), MYMAIL_VERSION, true);
this way you can
function my_remove_jquery(){
   return array ();
}
add_filter('mymail_no_jquery', 'my_remove_jquery');
This doesn’t help if the falsely used jQuery version is below your required version
378 posts
  • Became a Top 20 Author of the Month
  • Elite Author: Sold more than $75,000 on Envato Market
  • Had an item that became a weekly top seller
  • Had an item that was trending
+7 more
halfdata
says
I always use only WP native jQuery:
wp_enqueue_script("jquery");
1466 posts
  • Had an item that was trending
  • Won a Most Wanted contest
  • Has sold $10,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+8 more
greenline
says

I always use only WP native jQuery:
wp_enqueue_script("jquery");
I also used that, but I have a soft rejected item. One of the issues specified in the rejection email is
Please do not deregister or ignore the default version of jQuery being used by the theme and load a custom version.

So what shoud I do to make it the correct way?

492 posts here for love
  • Became a Top 20 Author of the Month
  • Had an item that was trending
  • Had an item that became a weekly top seller
  • Has sold $250,000+ on Envato Market
+10 more
nCrafts
says

I am not sure it’s a good idea to rely on WP for jQuery. As someone pointed out, WP loads jQuery by default only after a certain version.

I deregister jQuery and then enqueue it.
As far as noconflict is concerned, I use jQuery.noConflict(); and then use jQuery(’#id’) instead of $(’#id’)
I like this thread. I really hope we can come up with an ideal standard.

1466 posts
  • Had an item that was trending
  • Won a Most Wanted contest
  • Has sold $10,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+8 more
greenline
says

Thanks for the answers… But is there any developer online who used a correct include in a plugin which was accepted on CC? Can he/she please tell us the exact way of doing this? I am still confused how should I include the jquery js at the begiing of my plugin withour breaking other plugins or the theme. Thanks

by
by
by
by
by
by