Most tutorials that show you how to remove jquery from wordpress give you a reckless three-line wp_deregister_script( 'jquery' ) snippet that silently breaks the moment a contact form, lightbox, or WooCommerce cart script expects window.jQuery to exist. Even worse, calling wp_deregister_script( 'jquery' ) without checking $wp_scripts dependency chains can break wp-admin or leave dependent plugin scripts dead in the queue. Below is the safe engineering approach: auditing what actually requests jquery on your front end, removing jquery-migrate first, conditionally dequeueing jquery only when zero enqueued scripts depend on it, and replacing legacy jQuery idioms with modern vanilla JavaScript.
Table of Contents
- Quick Answer: Conditionally Dequeue jQuery Only When Safe
- How WordPress Core Registers jquery, jquery-core, and jquery-migrate
- Dependency Audit Flow: Deciding Whether jQuery Can Be Removed
- Step 1: Audit Which Plugins Depend on jQuery
- Step 2: Remove jquery-migrate on the Front End First
- Step 3: Guarded Front-End Dequeue (Auto-Fallback When Needed)
- When You Should NOT Remove jQuery From WordPress
- Vanilla JavaScript Replacements for Common jQuery Patterns
- How to Measure the Front-End Impact Yourself
- Frequently Asked Questions
Quick Answer: Conditionally Dequeue jQuery Only When Safe
Instead of blindly deregistering jQuery and praying no plugin breaks, inspect the active wp_scripts() queue at late priority (99) on wp_enqueue_scripts. If any enqueued script declares jquery or jquery-core in its deps array, leave jQuery intact; if nothing depends on it, dequeue it cleanly:
<?php /** * Plugin Name: Kinetix Safe Front-End jQuery Dequeue * Description: Dequeues jQuery on the front end only when no active script in the queue depends on it. */ defined( 'ABSPATH' ) || exit; add_action( 'wp_enqueue_scripts', function (): void { if ( is_admin() || is_customize_preview() ) { return; } $scripts = wp_scripts(); // 1. Always strip jquery-migrate from the front-end jquery bundle. if ( isset( $scripts->registered['jquery'] ) ) { $scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) ); } // 2. Check whether any currently enqueued script depends on jquery or jquery-core. foreach ( $scripts->queue as $handle ) { if ( 'jquery' === $handle || 'jquery-core' === $handle ) { continue; } $item = $scripts->registered[ $handle ] ?? null; if ( $item && array_intersect( array( 'jquery', 'jquery-core' ), (array) $item->deps ) ) { return; // A queued script needs jQuery on this URL — keep it loaded! } } wp_dequeue_script( 'jquery' ); wp_dequeue_script( 'jquery-core' ); wp_dequeue_script( 'jquery-migrate' ); }, 99 ); How WordPress Core Registers jquery, jquery-core, and jquery-migrate
To understand why naive snippets fail, look at how WordPress core registers jQuery inside wp-includes/script-loader.php:
-
jqueryis an empty alias handle (src = false) whose only job is to declare two dependencies:array( 'jquery-core', 'jquery-migrate' ). -
jquery-coreis the actual/wp-includes/js/jquery/jquery.min.jslibrary file. -
jquery-migrateis/wp-includes/js/jquery/jquery-migrate.min.js, a compatibility shim for deprecated jQuery 1.x/2.x APIs that modern code no longer uses.
Because jquery is a dependency alias, two rules apply whenever you touch it:
- Never deregister
jqueryinsidewp-admin,wp-login.php, or the Customizer. WordPress core's admin tables, media library modal (wp.media), Quick Edit, and Customizer controls depend heavily on jQuery and jQuery UI. In fact,wp_deregister_script()contains a hardcoded safeguard in core that blocks deregisteringjqueryinsideis_admin(). - Understand
wp_dequeue_script()vswp_deregister_script(). Callingwp_deregister_script( 'jquery' )deletes the handle from$wp_scripts->registered. If a plugin enqueued a script with'deps' => array( 'jquery' ), deregisteringjquerycauses WordPress to drop that plugin's script from output altogether because its dependency no longer exists! Callingwp_dequeue_script( 'jquery' )after verifying zero dependents is much safer.
Dependency Audit Flow: Deciding Whether jQuery Can Be Removed
Before changing any enqueue hooks, trace the script dependency tree on each major template of your site (Homepage, Blog Post, Contact Page, Shop/Checkout).
flowchart TD A["Action: wp_enqueue_scripts (Priority 99)"] --> B{"Is Admin, Login, or Customizer Preview?"} B -- "Yes" --> C["Keep jQuery & jQuery Migrate untouched"] B -- "No (Public Front End)" --> D["Remove 'jquery-migrate' from $wp_scripts->registered['jquery']->deps"] D --> E["Walk all handles in $wp_scripts->queue (and recursive deps)"] E --> F{"Does any queued script depend on 'jquery' or 'jquery-core'?"} F -- "Yes (e.g., WooCommerce Cart / 3rd-Party Form)" --> G["Keep 'jquery-core' loaded on this URL"] F -- "No (Pure Vanilla JS Theme & Blocks)" --> H["Call wp_dequeue_script('jquery') & wp_dequeue_script('jquery-core')"] H --> I["Zero jQuery bytes shipped to browser"] Step 1: Audit Which Plugins Depend on jQuery
Don't guess which plugin is pulling jQuery onto your pages. Add this temporary diagnostic helper (visible only to logged-in administrators when you append ?kx_audit_scripts=1 to any front-end URL) to print every enqueued script that lists jquery or jquery-core in its dependency chain:
<?php /** * Append ?kx_audit_scripts=1 as an administrator to print an HTML comment listing all jQuery dependents. */ defined( 'ABSPATH' ) || exit; add_action( 'wp_print_footer_scripts', function (): void { if ( is_admin() || ! isset( $_GET['kx_audit_scripts'] ) || ! current_user_can( 'manage_options' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } $scripts = wp_scripts(); $dependents = array(); foreach ( $scripts->done as $handle ) { $obj = $scripts->registered[ $handle ] ?? null; if ( ! $obj ) { continue; } if ( array_intersect( array( 'jquery', 'jquery-core', 'jquery-migrate' ), (array) $obj->deps ) ) { $dependents[ $handle ] = (string) $obj->src; } } echo "\n<!-- [Kinetix jQuery Dependency Audit]\n"; if ( empty( $dependents ) ) { echo "No printed scripts declared a dependency on jquery.\n"; } else { foreach ( $dependents as $h => $src ) { printf( " - Handle: %-32s | Source: %s\n", esc_html( $h ), esc_html( $src ) ); } } echo "-->\n"; }, 999 ); Load your homepage or blog post while logged in as an admin with ?kx_audit_scripts=1 and view the page source at the bottom of <body>. You will see the exact handle name (for example, wc-add-to-cart or contact-form-7) and file path responsible for pulling jQuery into the request.
Step 2: Remove jquery-migrate on the Front End First
Even on sites where one legacy plugin still needs jquery-core, almost no modern front-end script needs jquery-migrate.min.js. Stripping jquery-migrate from the jquery bundle dependency array removes an extra synchronous script file from <head> while keeping window.jQuery and window.$ 100% functional for plugins that need jQuery 3.x:
/** * Remove jquery-migrate from the front-end 'jquery' bundle. */ add_action( 'wp_default_scripts', function ( WP_Scripts $scripts ): void { if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) { $script = $scripts->registered['jquery']; if ( ! empty( $script->deps ) ) { $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) ); } } } ); After adding that hook, open Chrome DevTools Console and click through your key pages. If zero JQMIGRATE or Uncaught TypeError errors appear, your site has no dependency on deprecated jQuery 1.x methods.
Why Removing jQuery Migrate Alone Helps Main-Thread Parsing
Even though jquery-migrate.min.js is only around 13.6 KB uncompressed (~5 KB over Brotli), WordPress loads it as a render-blocking script inside <head> right after jquery.min.js. On mobile CPUs, every synchronous script tag in <head> pauses the HTML parser while V8 or JavaScriptCore compiles and executes the file. Removing jquery-migrate eliminates an entire blocking HTTP request and script evaluation pass without changing a single line of plugin code that relies on standard jQuery 3.7 methods.
Step 3: Guarded Front-End Dequeue (Auto-Fallback When Needed)
To handle nested dependency chains (for example, Script A depends on Script B, and Script B depends on jquery), write a recursive dependency checker. If any script queued on the current URL directly or transitively depends on jquery or jquery-core, WordPress automatically keeps jquery-core loaded for that page; on every other page, jQuery is completely removed.
<?php /** * Recursively check whether a script handle or any of its dependencies require jQuery. * * @param string $handle Script handle to inspect. * @param WP_Scripts $scripts Global WP_Scripts instance. * @param array<string, bool> $visited Cycle guard map. */ function kx_script_needs_jquery( string $handle, WP_Scripts $scripts, array &$visited = array() ): bool { if ( isset( $visited[ $handle ] ) ) { return false; } $visited[ $handle ] = true; $item = $scripts->registered[ $handle ] ?? null; if ( ! $item || empty( $item->deps ) ) { return false; } foreach ( (array) $item->deps as $dep ) { if ( in_array( $dep, array( 'jquery', 'jquery-core' ), true ) ) { return true; } if ( kx_script_needs_jquery( (string) $dep, $scripts, $visited ) ) { return true; } } return false; } /** * Dequeue jQuery on the front end unless a queued script or inline after-script requires it. */ add_action( 'wp_enqueue_scripts', function (): void { if ( is_admin() || is_customize_preview() ) { return; } $scripts = wp_scripts(); foreach ( $scripts->queue as $handle ) { if ( in_array( $handle, array( 'jquery', 'jquery-core', 'jquery-migrate' ), true ) ) { continue; } if ( kx_script_needs_jquery( (string) $handle, $scripts ) ) { return; } } // Also check if a plugin attached inline JS directly to 'jquery' or 'jquery-core' via wp_add_inline_script(). foreach ( array( 'jquery', 'jquery-core' ) as $jq_handle ) { $after = $scripts->get_data( $jq_handle, 'after' ); $before = $scripts->get_data( $jq_handle, 'before' ); if ( ! empty( $after ) || ! empty( $before ) ) { return; } } wp_dequeue_script( 'jquery' ); wp_dequeue_script( 'jquery-core' ); wp_dequeue_script( 'jquery-migrate' ); }, 999 ); Look closely at that second check ($scripts->get_data( $jq_handle, 'after' )): some plugins call wp_enqueue_script( 'jquery' ) and then attach their JavaScript via wp_add_inline_script( 'jquery', 'jQuery(function($){ ... });' ) without registering a separate handle. Checking get_data( 'jquery', 'after' ) catches those inline scripts too!
When You Should NOT Remove jQuery From WordPress
Being a pragmatic engineer means knowing when removing a library is the wrong trade-off. Do not force-remove jquery-core on URLs that run the following:
| Scenario | Why It Still Needs jQuery | Better Optimization Path |
|---|---|---|
| Classic WooCommerce Cart, Checkout, and Variable Product Pages | Classic WooCommerce scripts (wc-add-to-cart-variation, wc-checkout, wc-cart-fragments, Select2/SelectWoo) are written in jQuery and trigger custom jQuery events (found_variation, updated_checkout). | Keep jQuery on cart/checkout/product pages, and dequeue WooCommerce scripts on non-commerce blog/content pages (covered in our WordPress speed optimization without a plugin guide). |
| Legacy Gravity Forms / Multi-Step Form Plugins | Conditional logic, datepickers, and AJAX submission handlers in many form plugins depend on jQuery.ajax and custom jQuery events. | Let the guarded dequeue above keep jQuery only on pages where the form shortcode/block is rendered. |
wp-admin and Block Editor | WordPress core admin screens, meta boxes, and wp.media rely on jQuery and jQuery UI. | Never run dequeue hooks when is_admin() is true. |
By contrast, if you run a studio portfolio, documentation site, academic lab, or editorial publication on a modern zero-jQuery theme like the Kinetix Theme—where navigation, glass controls, and dark mode toggles are written in pure vanilla JavaScript—nothing on the front end needs jQuery at all.
Vanilla JavaScript Replacements for Common jQuery Patterns
If your theme still loads jQuery just for a mobile menu drawer, an accordion, or an admin-ajax.php / REST fetch call, replace those patterns with standard DOM APIs supported in every browser:
| Task | Legacy jQuery Pattern | Modern Vanilla JavaScript Equivalent |
|---|---|---|
| DOM Ready | $(document).ready(fn) / $(fn) | <script defer> or document.addEventListener('DOMContentLoaded', fn) |
| Single / Multi Selector | $('.card') | document.querySelector('.card') / document.querySelectorAll('.card') |
| Class Toggle | $el.toggleClass('is-open') | el.classList.toggle('is-open') |
| Event Delegation | $(document).on('click', '.btn', fn) | document.addEventListener('click', e => { const btn = e.target.closest('.btn'); if (btn) fn(e, btn); }) |
| Closest Ancestor | $el.closest('.modal') | el.closest('.modal') |
| Fade / Slide Transition | $el.slideToggle(200) / $el.fadeIn() | CSS transition / grid-template-rows: 0fr -> 1fr + el.hidden or [data-open="true"] |
| AJAX / JSON Request | $.ajax({ url, method: 'POST', data }) | await fetch(url, { method: 'POST', body: new URLSearchParams(data) }) |
Here is a complete vanilla JavaScript replacement for a WordPress REST API or AJAX form submission with proper error handling and zero dependencies:
document.addEventListener('submit', async (event) => { const form = event.target.closest('[data-kx-async-form]'); if (!form) return; event.preventDefault(); const statusEl = form.querySelector('[data-kx-status]'); const submitBtn = form.querySelector('[type="submit"]'); if (submitBtn) submitBtn.disabled = true; try { const response = await fetch(form.action, { method: 'POST', headers: { 'X-WP-Nonce': form.dataset.nonce || '', }, body: new FormData(form), }); if (!response.ok) { throw new Error(`HTTP ${response.status}`); } const result = await response.json(); if (statusEl) { statusEl.textContent = result.message || 'Submitted.'; } form.reset(); } catch (error) { if (statusEl) { statusEl.textContent = 'Request failed. Please try again.'; } } finally { if (submitBtn) submitBtn.disabled = false; } }); How to Measure the Front-End Impact Yourself
Instead of trusting generic benchmark claims, verify the exact byte and parse-time reduction on your own WordPress install in under two minutes:
- Chrome DevTools Network Tab (JS Filter):
- Open your page in an Incognito window (so
admin-bar.min.jsis not loaded). - Open DevTools → Network → JS, check Disable cache, and reload.
- Look for
/wp-includes/js/jquery/jquery.min.jsand/wp-includes/js/jquery/jquery-migrate.min.js. Record the transferred size (gzip/Brotli) and uncompressed resource size before and after activating your guarded dequeue hook.
- Open your page in an Incognito window (so
- Chrome DevTools Coverage Tab (
Ctrl+Shift+P→Show Coverage):- Click the reload button inside the Coverage drawer.
- If
jquery.min.jswas previously showing 85%–100% unused bytes on content pages, removing it eliminates both the network download and the main-thread script evaluation cost in<head>.
Troubleshooting: "Uncaught ReferenceError: jQuery is not defined" from an inline script in the footer
If a plugin prints raw jQuery(document).ready(...) directly inside a wp_footer action hook instead of using wp_enqueue_script() with 'deps' => array( 'jquery' ), $wp_scripts has no way of knowing that plugin needs jQuery.
- Best fix: Rewrite that small inline snippet in vanilla JavaScript (
document.addEventListener('DOMContentLoaded', ...)), or register it properly withwp_add_inline_script(). - Fallback fix: If the inline script comes from a third-party plugin on a specific page slug (e.g.,
/booking), addif ( is_page( 'booking' ) ) { wp_enqueue_script( 'jquery' ); return; }at the top of your dequeue callback.
Frequently Asked Questions
Why is jQuery still loaded in the WordPress head instead of the footer?
WordPress core registers jquery-core in <head> (without in_footer) because thousands of older plugins print inline <script>jQuery(...)</script> blocks directly inside the post content body (the_content) before wp_footer() runs. Moving jQuery to the footer only works if zero inline scripts in <body> reference jQuery or $ synchronously during HTML parsing.
Does the WordPress Block Editor (Gutenberg) require jQuery on the front end?
No. Core Gutenberg blocks (Navigation, Image Lightbox, Query Pagination, Details/Accordion, and the WordPress 6.5+ Interactivity API) run on standalone ES modules and vanilla JavaScript on the front end. Only legacy third-party block plugins enqueue jQuery.
Is it safe to replace WordPress's bundled jQuery with a public CDN version?
No. Replacing core's /wp-includes/js/jquery/jquery.min.js with an external CDN (code.jquery.com or cdnjs) is discouraged by the WordPress Theme and Plugin Review Teams. After modern browsers partitioned HTTP caches by top-level origin, external CDNs no longer share cached files across different websites, and instead add an extra DNS lookup and TLS handshake. Either use core's bundled jQuery when a plugin requires it, or dequeue it cleanly when nothing depends on it.
Related Guides
- Remove WordPress Bloat: Emojis, Dashicons & oEmbed — Strip unused WordPress core frontend assets—emojis, Dashicons for guests, and oEmbed scripts—with 25 lines of clean PHP 8.2+ wp_enqueue hooks.
Originally published at https://kinetix.software/blog/wordpress-remove-jquery.
