Questions & Answers

Inheritance with wp_enqueue_scripts()

I'm trying to build a plugin in wordpress, and I've encountered this issue where I need to include a .js from another plugin into my own. I tried it using wp_enqueue_script() by adding the other .js as a dependency for my .js, but to no avail.

wp_enqueue_script('parent-script', '/parent-script.js', array('jquery', 'parent-script'), false);
wp_enqueue_script('child-script', '/child-script.js', array('jquery', 'parent-script'), false);

I need to call a variable from the parent-script and use it in the child-script. Is it possible? If so, how do I proceed with it?

2023-01-20 23:01:06
The parent script must not list itself as a dependency of itself, only the child script should do this.
Answers(0) :