How to override prepended JavaScript files in child themes?

I’m trying to override from my child theme some JavaScript, which is in a parent theme’s .js file. The .js file in question is not being loaded through a PHP hook, but rather from another .js file (the parent theme’s main scripts.js file). It’s full of //@prepros-prepend commands calling other JS files, including the one I want to override, using relative paths like so:

//@prepros-prepend components/wc-product-gallery.js

I only need to change one true value to a false one inside an if statement in wc-product-gallery.js. I tried copying the relevant code into my child theme’s custom-scripts.js that gets properly enqueued, but it doesn’t override the parent theme’s code.

I could, in theory, dequeue the parent theme’s scripts.js and enqueue a modified version from the child theme, but then how do I go about the relative paths to make sure only one prepended file is loaded from the child theme directory, and all the other ones keep getting loaded from the parent theme, and at the right time as well?

Read more here:: How to override prepended JavaScript files in child themes?

Leave a Reply

Your email address will not be published. Required fields are marked *