21 posts
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 3-4 years
  • Russian Federation
  • Referred between 50 and 99 users
  • Bought between 10 and 49 items
  • Exclusive Author
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.

1466 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
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.

366 posts
  • Elite Author
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
  • Attended a Community Meetup
  • Bought between 100 and 499 items
+4 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
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 3-4 years
  • Russian Federation
  • Referred between 50 and 99 users
  • Bought between 10 and 49 items
  • Exclusive Author
Yatek says

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

913 posts
  • Author had a Free File of the Month
  • Football Contest Participant/Runner-up
  • Grew a moustache for the Envato Movember competition
  • Sold between 10 000 and 50 000 dollars
  • Beta Tester
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Bought between 50 and 99 items
  • Referred between 1 and 9 users
+2 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.

2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 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
225 posts
  • Elite Author
  • Author had a File in an Envato Bundle
  • Sold between 100 000 and 250 000 dollars
  • Referred between 200 and 499 users
  • Exclusive Author
  • Bought between 1 and 9 items
  • Has been a member for 2-3 years
  • Europe
ichurakov says
I always use only WP native jQuery:
wp_enqueue_script("jquery");
913 posts
  • Author had a Free File of the Month
  • Football Contest Participant/Runner-up
  • Grew a moustache for the Envato Movember competition
  • Sold between 10 000 and 50 000 dollars
  • Beta Tester
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Bought between 50 and 99 items
  • Referred between 1 and 9 users
+2 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?

434 posts here for love
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 1-2 years
  • India
  • Won a Competition
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
+2 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.

913 posts
  • Author had a Free File of the Month
  • Football Contest Participant/Runner-up
  • Grew a moustache for the Envato Movember competition
  • Sold between 10 000 and 50 000 dollars
  • Beta Tester
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Bought between 50 and 99 items
  • Referred between 1 and 9 users
+2 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