Tips and Tricks HQ Support Portal › Forums › General Stuff › Instructions/F.A.Q › Wrong Way of adding JQuery library to WordPress – Source of Javascript Conflicts
- This topic has 0 replies, 1 voice, and was last updated 13 years, 7 months ago by amin007.
-
AuthorPosts
-
April 29, 2011 at 6:44 am #2568amin007Participant
We see a lot of themes and plugins not using the WordPress script enqueue function to include the popular JQuery library (this is recommended by WordPress):
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
The developer seem to just include the library and test it on his site where a minimal number of plugin is running so he never sees the problem. The developer should be enqueuing the jQuery library that comes with WordPress to avoid conflicts with other plugins or themes. The 3rd example of this article explains the issue in more details:
When Themes Go Wild – Importance of Using a Properly Coded WordPress Theme
This issue is widely seen in themes or plugins developed by developers who just want to quickly make something eye catchy and then move on (without looking at the bigger picture or thinking about the future, performance or user experience). For example, the developer should be asking the following questions before blindly including a static version of JQuery library in his theme or plugin :
– What will happen when a new version of WordPress is released?
– What will happen with a new version of JQuery library is released?
– Will my user suffer? Am I doing the right thing?
– How can I implement my solution so I am not polluting the user’s WordPress environment?
If you do want to use a particluar jquery library (for example: the one from Google) then your script should deregister the other JQuery engueue that comes from WordPress so that two instances of the library is not loaded on the page. Some theme developers seem to forget that the theme is not the only thing that will run on a WordPress site. It will share the space with other plugins so it needs to be coded in a way that lets everyone to coexist nicely.
Note: Loading multiple copies of the same library not only causes plugin/theme conflict, it also slows your site down since the webpage is loading the same resource twice. So for the sake of your site’s performance you should make sure that your theme or plugin developer does not give you an improperly coded theme or plugin.
Isolating the Source of the Issue
You can do the test mentioned here to find out which theme or plugin is doing this:
https://support.tipsandtricks-hq.com/forums/topic/test-to-identy-a-conflicting-theme-or-plugin
-
AuthorPosts
- The topic ‘Wrong Way of adding JQuery library to WordPress – Source of Javascript Conflicts’ is closed to new replies.