I´ve been struggling with this for nearly a month now and still couldn´t find anything at all on how to do this! Not here, not in Quora, not through many different advanced Google search queries...
Here it is:
The parent theme has only one script file main.min.js
. It contains all the scripts and libraries being used by it, including jQuery
, Select2
, Parsley
and Slick
, to name a few.
How do I go about making my own scripts use one or more of these libraries as their dependencies in the child theme?
The immediatelly obvious approach is to declare the parent theme main.min.js
as the dependency when enqueueing my own scripts in the child´s functions.php
and make sure my scripts fire after the dependency has been loaded on the page.
I´ve done that, yet, it doesn´t work. My scripts cannot access their dependencies.
The only alternative I can think of is enqueueing all these libraries separately in the child theme, as if the parent didn´t have them. Which is clearly a horrible thing to do, as the parent theme will load these libraries in its main js file too!
So there must be a way to do this by using the already provided libraries in the parent.
Had the parent theme enqueued the libraries separately this would be easy. I guess the main issue here is that all scripts and libraries are included in one single js file.
Any help would be immensely appreciated!