Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

If a Plugin is coded properly, it will:

  1. Use core-bundled jQuery, and any other core-bundled script, rather than bundling/using custom versions of such scripts
  2. enqueue its scripts, via wp_enqueue_script(), hooked into an appropriate hook, via an explicit function

So, for such a Plugin:

  1. You won't need to worry about customizing/overriding core-bundled scripts, since the Theme will be using the core-bundled versions as well
  2. You can override custom scripts bundled with the Plugin by dequeueing the Plugin's scripts, and enqueueing your own custom versions

To override a Plugin's scripts, you have a few options:

  1. Call remove_action() to remove the entire callback that contains the wp_enqueue_script() calls
  2. Call wp_dequeue_script() to prevent the script from being enqueued, followed by a wp_enqueue_script() call to enqueue your own script.
  3. Call wp_deregister_script(), followed by wp_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
share|improve this answer
    
I like the answer; very informative and not too far from my thoughts. Nice to know I was on the right track. Any issue(s) with loading/queuing order with this approach? –  Stephen Nov 16 '12 at 23:54
    
"Any issue(s) with loading/queuing order with this approach?" - Possibly. You'll need to dequeue from the same action, at the same priority. If you remove_action(), you'll just need to make sure you call it after the add_action(). –  Chip Bennett Nov 16 '12 at 23:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.