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.
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.
- Author was Featured
- Item was Featured
- Author had a File in an Envato Bundle
- Microlancer Beta Tester
- Exclusive Author
- Most Wanted Bounty Winner
- Attended a Community Meetup
- Bought between 100 and 499 items
@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 
thanks @OriginalEXE & @RightHere
Good points you made
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.
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
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
wp_enqueue_script("jquery");
ichurakov saidI also used that, but I have a soft rejected item. One of the issues specified in the rejection email is
I always use only WP native jQuery:wp_enqueue_script("jquery");
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?
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.
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
