I’m modifying some functionality of a theme i’m using, which already set up a .js
file inside a plugin to handle the paypal checkout process. I had to modify the code so I renamed a few elements and basically copied the old js file to a new file and made the changes.
It works and everything is fine, but I wonder if there’s a better way to do it in WordPress? It doesn’t feel right to modify so much just so I could change a few lines of code inside.
Thanks!
Extending the above comment:
Directly changing the files of the plugin or theme is not a good practice as once the plugin/theme is updated, you will loose the changes. Instead use child theme in case of themes and hook to required actions in case of plugins.
In your case since you are only changing the script in plugin and they might have enqueued(they should be) with wp_enqueue_script
hooked to wp_enqueue_scripts
. You can dequeue that script using wp_dequeue_script
all you have to do is findout the script handle from the original plugin. Then you need to enqueue the changed script.