Skip to content

WordPress JavaScript errors from plugins: isolation and fix patterns

WordPress JS errors from a plugin usually point at one of three patterns. Here is how to isolate the offending WordPress plugin without disabling the whole site.

When a WordPress plugin’s JS breaks, it tends to break loud — a slider doesn’t render, a form won’t submit, a gallery lightbox does nothing. The console error names a file. Tracing that file back to the responsible plugin is straightforward; figuring out which other plugin or theme conflicted is the harder half.

What’s happening

JavaScript in WordPress is enqueued in a strict order. WordPress core scripts first, then themes, then plugins in the order they were activated. The page renders all of them in <head> or before </body> based on each script’s enqueue position. A plugin that assumes jQuery 1.x but loads after another plugin that ships jQuery 3.x will throw at runtime. A plugin that registers a global variable name another plugin uses will overwrite it.

The three classic conflict patterns: namespace pollution (two plugins both define window.myPlugin), event handler clobbering (one plugin’s .click() handler removes another’s), and version skew (one plugin loads its own copy of a library that another plugin expects in a different version). The console error names the file that errored, but the cause is often a different file higher in the load order.

How to verify

# Get the script load order from the rendered page:
curl -s https://example.com/ | grep -oE '<script[^>]+src="[^"]+"' | nl

# List every enqueued plugin script with WP-CLI:
wp eval '
  global $wp_scripts;
  foreach ($wp_scripts->registered as $h => $s) {
    if (strpos($s->src, "plugins") !== false) {
      echo "$h => $s->src\n";
    }
  }
'

# Disable plugins one at a time:
wp plugin deactivate slow-plugin
# Reload, check console
wp plugin activate slow-plugin

In DevTools, set a breakpoint on the failing line. The Call Stack panel shows which scripts called into the failing function — that’s your conflict chain.

The fix

  1. Read the error file path. “Uncaught TypeError in /wp-content/plugins/foo-slider/main.js:42” — start with foo-slider. Check its version, check its requirements, check the WordPress.org plugin page for known conflicts.
  2. Bisect plugins. Deactivate half, reload, check console. If error gone, the conflict is in the deactivated half. Repeat until you find the pair.
  3. Check for jQuery noConflict patterns. Many old plugins use $ directly when jQuery is in noConflict mode (which is WordPress default). The fix is wrapping the plugin’s code in jQuery(function($) { ... }). If the plugin author won’t fix, a small mu-plugin can intercept and wrap.
  4. Use script_loader_tag to reorder. If plugin A must load before plugin B, the script_loader_tag filter lets you adjust without editing plugin files. Or use wp_enqueue_script with explicit dependencies.
  5. Check for double-enqueued libraries. Two plugins each enqueueing their own Slick Carousel breaks both. Use wp_dequeue_script in mu-plugins to drop the duplicate.
  6. Disable browser caching while diagnosing. Hard refresh (Cmd+Shift+R) and uncheck “Disable cache” in DevTools Network panel. Otherwise the old broken version stays loaded.

For sites with plugin-heavy front ends where JS conflicts recur after updates, Stack Harbor catches them in enterprise WordPress hosting CI. For help isolating a current conflict, book a consult.