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.


  • 1
    Don't change the plugin code directly.. dequeue the plugin .js and enqueue the changed .js
    – bravokeyl
    Sep 19, 2016 at 12:34
  • 1
    Dequeue the script was just what I was looking for... cheers!
    – user102853
    Sep 19, 2016 at 12:44

2 Answers 2


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.


Same problem here, but "wp_dequeue_script" was not enough. I wanted to override the "waypoints" loaded by WPBakery plugin. Adding "wp_deregister_script" the code is working.

define( 'MY_CHILD_URI', get_stylesheet_directory_uri().'/' );

add_action('wp_enqueue_scripts', 'mytheme_scripts');

function mytheme_scripts() {
  wp_dequeue_script( 'waypoints' );
  wp_deregister_script( 'waypoints' );
  wp_enqueue_script( 'waypoints',  MY_CHILD_URI . 'assets/js/jquery.waypoints.min.js', array('jquery'), '', true );
  • Thanks for sharing the answer Nov 13, 2020 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy