21 posts
  • Has referred 50+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
+2 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.

1484 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
+3 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.

370 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Located in United States
  • Has sold $250,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
+9 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 ;)

21 posts
  • Has referred 50+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
+2 more
Yatek says

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

1023 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Contributed a free file of the month
+6 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.

2028 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Provided great feedback to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+9 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
262 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Had an item featured in an Envato Bundle
+5 more
ichurakov says
I always use only WP native jQuery:
wp_enqueue_script("jquery");
1023 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Contributed a free file of the month
+6 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?

445 posts here for love
  • Has sold $125,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Won a competition
  • Sells items exclusively on Envato Market
+7 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.

1023 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Contributed a free file of the month
+6 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