# Load a different jQuery version on specific pages

URL: https://wp24x7.com/load-multiple-jquery-versions/
Updated: 2026-11-29
Type: blog post
Audience: WordPress developers maintaining legacy plugins or widgets

> When a legacy plugin or widget needs an old jQuery on one page, do not replace WordPress's jQuery. Load the old copy as a second script under its own handle and variable with jQuery.noConflict( true ), only on the pages that need it, and plan its removal. The better fixes are to update the plugin, use the Migrate helper on staging or patch removed calls.

## Key facts

- For: developers who must run an old jQuery on specific pages
- Pattern: second script depending on jquery, then jQuery.noConflict( true ) into window.jQueryLegacy
- Never: deregister the handle jquery or load a different jQuery in the admin
- Costs: extra bytes, parse time, old security weaknesses, $ conflicts
- Better first: update the plugin, test the Migrate helper, patch removed calls
- Safety: back up, test on staging, set a removal date
- Help: WordPress development and care plans

Sometimes one page needs an old jQuery because a legacy plugin or widget has not been updated. **Do not replace WordPress's jQuery. Load the old copy as a second script under its own variable, only on the pages that need it, and plan to remove it.**

> **Quick answer**
Register the old file under a different handle that depends on `jquery`, then run `jQuery.noConflict( true )` into `window.jQueryLegacy`. Front end only, narrowest page condition, with a removal date. Back up and test on staging.

## When does this make sense?

Rarely, and only as a bridge: an abandoned plugin that calls jQuery methods removed years ago, or a third-party embed on a single landing page. The preferred fix is always to update or replace the old code. See the [$.browser error guide](/how-to-fix-browser-undefined-error-in-wordpress) and the [Bootstrap 3 version error](/how-to-fix-bootstraps3-jquery-error).

## What are the alternatives, in order?

| Order | Alternative | Note |
|---|---|---|
| 1 | Update or replace the legacy plugin | Cleanest, often quickest |
| 2 | jQuery Migrate helper on staging | Restores many removed methods without a second copy |
| 3 | Patch your own code | Replace `.live()` with `.on()`, `.size()` with `.length`, `$.browser` with feature detection |
| 4 | Isolate in an iframe | The old library lives in its own page |
| 5 | Load a second copy | Scoped to the pages that need it |

Costs of a second copy: more bytes and parsing, old versions' published security problems (mostly cross-site scripting) and two copies fighting over `$` and `jQuery`.

## Why not swap the bundled jQuery?

WordPress registers jQuery under the handle `jquery`, which pulls in `jquery-core` and sometimes a Migrate helper. Hundreds of scripts depend on that handle. If you deregister it and register another file under the same name, every dependent script receives the replacement, including ones that cannot run on it. The admin and block editor are especially sensitive, so never do this globally and never in the admin.

## How do I load a second copy on selected pages?

Put the old file in a child theme or small plugin, for example `js/jquery-1.12.4.min.js` (use the version your legacy code needs). Register it as a different handle that depends on `jquery`, so it loads after core's copy:

```php
add_action( 'wp_enqueue_scripts', function () {
	// Change the condition: a page slug, a template, a category, and so on.
	if ( ! is_page( 'legacy-landing' ) ) {
		return;
	}

	wp_enqueue_script(
		'jquery-legacy',
		get_stylesheet_directory_uri() . '/js/jquery-1.12.4.min.js',
		array( 'jquery' ),
		'1.12.4',
		true
	);

	// Give the old copy its own name and hand $ and jQuery back to core's copy.
	wp_add_inline_script( 'jquery-legacy', 'window.jQueryLegacy = jQuery.noConflict( true );' );
}, 20 );
```

The old file loads second and sets `window.jQuery` and `window.$` to itself. `jQuery.noConflict( true )` restores the previous values and returns the old copy, stored as `jQueryLegacy`. Core scripts keep using the original `jQuery`. Your legacy code must use that name, not `$`:

```js
( function ( $ ) {
	// old plugin code runs against the legacy copy
	$( '.old-slider' ).oldSlider();
} )( window.jQueryLegacy );
```

If the old plugin attaches itself to `jQuery.fn` at load time, it must load while the legacy copy is still the global `jQuery`, before `noConflict` runs. That means its script has to be enqueued between the legacy file and the inline script, which usually means changing how the plugin loads. If you cannot control the order, fix or replace the plugin instead.

## How do I choose the page condition?

Use the narrowest condition that works:

### One page
`is_page( 'slug' )` for a single page.
### Custom post type
`is_singular( 'landing' )` for a custom post type.
### By shortcode
`has_shortcode( get_post()->post_content ?? '', 'old_widget' )` only when the content contains a specific shortcode. Check `get_post()` is not null first.

Never use conditions that match the whole site: that defeats the purpose and slows every page.

## How do I test it?

1. **Use a staging copy** with the browser console open.
2. **Confirm versions.** `jQuery.fn.jquery` shows core's version and `jQueryLegacy.fn.jquery` the old one.
3. **Test the legacy widget,** then the rest of the page: menus, forms, sliders.
4. **Check optimizers.** Minifiers and "delay JavaScript" features can reorder scripts and break the `noConflict` sequence. Exclude both jQuery files.

## What can go wrong?

| Problem | Why | Fix |
|---|---|---|
| Plugin binds at load time | It registers on whichever copy is global at that moment | Check the order in the page source |
| Caching and combining | Concatenation moves the inline snippet away from its file | Exclude both files |
| Different versions in the admin | The condition must be front end only | Keep it that way |
| Extra bytes | A second library is roughly the size of the first again | Scope tightly, retire early |
| Security | Old versions have known weaknesses | Never feed user-supplied HTML into them |

## Worked example: a legacy slider on one landing page

A campaign landing page uses an old slider plugin that needs jQuery 1.12 and fails on core's version. The plugin cannot be replaced before launch. The team adds the snippet for that one page, confirms `jQuery.fn.jquery` still reports core's version and tests the form. The slider's init code uses `jQueryLegacy`. Every other page is unaffected, and a ticket is opened to replace the slider by a set date. Without that date, the workaround tends to stay for years.

## How do I record it and get rid of it?

Add a comment above the code that says why it exists, which page it affects and the date it should go, and a line to the site's change log. Add a calendar reminder: the workaround should end when the legacy plugin is updated or replaced. A [care plan](/wordpress-maintenance-service) catches this kind of debt before it grows, and our [WordPress development](/wordpress-development) team can rewrite old widgets for current jQuery or plain JavaScript.

**Stuck with a legacy widget?**
Our developers can update or replace it.
[Post a project](/post-project)
[WordPress support](/wordpress-support)

## Frequently asked questions

### Is it safe to replace WordPress's jQuery on one page?

It is risky. Plugins on that page expect the bundled version. Loading a second copy under its own variable with noConflict is the safer pattern, and it should be temporary.

### Why not deregister jquery and register an old one?

Core, block features and plugins depend on the handle named jquery. Swapping it affects every script that lists it as a dependency and often breaks the admin or the front end.

### Does this affect Core Web Vitals?

Yes. A second jQuery file is extra bytes and parse time on those pages. That is another reason to load it only where needed and to retire it.

### What is jQuery.noConflict( true ) doing here?

It gives back the global jQuery and $ that existed before the old copy loaded, and returns the old copy so you can keep it under its own name.

### What should I try before loading a second jQuery?

Update or replace the legacy plugin, test the jQuery Migrate helper on staging, patch your own code to replace removed calls, or isolate the old widget in an iframe. Load a second copy only as the last resort.

### How do I scope it to the right page?

Use the narrowest condition: is_page( 'slug' ) for one page, is_singular() for a custom post type, or has_shortcode() only when the content holds a specific shortcode. Never match the whole site.

### How do I confirm the right version is in use?

In the browser console, jQuery.fn.jquery should show core's version and jQueryLegacy.fn.jquery the old one. Then test the legacy widget and the rest of the page.

### Why does the legacy plugin still fail?

If it attaches itself to jQuery.fn at load time, it must load while the legacy copy is still the global jQuery, before noConflict runs. If you cannot control its loading order, this approach may not work and the plugin should be fixed or replaced.

### Can caching or optimization plugins break this?

Yes. Minifiers, combiners and delay JavaScript features can reorder scripts or move the inline snippet. Exclude both jQuery files from those features.

### Is it a security risk to load an old jQuery?

Old versions have published weaknesses, mostly around cross-site scripting. Load one only on pages where untrusted input is not handled by jQuery, and never feed user-supplied HTML into it.

### How do I make sure the workaround ends?

Add a comment saying why it exists, which page it affects and the date it should go, record it in the site's change log and set a calendar reminder.
