Include third party Javascript library which is not included in WordPress

I want to include a third partrty Javascript library, LeafletJS in particular, into my WordPress plugin. I thought it woulnd’t be a good idea just to include it without thinking about what happens if an other plugin includes the same library. Perhaps even in an other (major) version.
I found out that WordPress already has many popular Javascript librarys included. If I want to use one of those I just have to tell WordPress to load these librarys. If every plugin developer does it like this there won’t be any problems and every plugin is using the same version of those librarys.
When I searched the web for how I should include third party librarys I only found many results that described this way. But that won’t help me.

What if I want to include a Javascript library which is not already included in WordPress? Is there any way my plugin won’t have any conflicts with other plugins that include the same library?
Right now I have this problem with a plugin, but it would be nice to have a solution which also works if I have this problem with a theme.

2 s
2

You need to use wp_script_is in order to check if the library you are willing to use has already been included by another plugin. As you can see the handle is important, if you change it to whatEverIWant.js, it will not recognize the library.

Leave a Comment