Most well written plugins support a safe means for a developer to customize/theme the plugin by copying PHP files to the theme directory and modifying the copies rather than the original plugin file. But, unless I’m overlooking something, I’m not aware of any that support this with JavaScript/jQuery files.
What is the best practice or approach for customizing the plugin’s JavaScrpt/jQuery files in an upgrade safe
manner?
If a Plugin is coded properly, it will:
wp_enqueue_script()
, hooked into an appropriate hook, via an explicit functionSo, for such a Plugin:
To override a Plugin’s scripts, you have a few options:
remove_action()
to remove the entire callback that contains thewp_enqueue_script()
callswp_dequeue_script()
to prevent the script from being enqueued, followed by awp_enqueue_script()
call to enqueue your own script.wp_deregister_script()
, followed bywp_register_script()
(with the same script$handle
to allow your own custom version to be registered, and enqueued in place of the Plugin’s version