Skip to content
Development

Load a different jQuery version on specific pages

How to load a second jQuery build on chosen pages without breaking core, using noConflict, correct dependencies and the risks you accept.

By WP24×7 engineers5 min readPublished January 5, 2021Updated November 29, 2026

At a glance

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.

Updated November 29, 2026 · For WordPress developers maintaining legacy plugins or widgets

  • 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.

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 and the Bootstrap 3 version error.

What are the alternatives, in order?

OrderAlternativeNote
1Update or replace the legacy pluginCleanest, often quickest
2jQuery Migrate helper on stagingRestores many removed methods without a second copy
3Patch your own codeReplace .live() with .on(), .size() with .length, $.browser with feature detection
4Isolate in an iframeThe old library lives in its own page
5Load a second copyScoped 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:

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 $:

( 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:

is_page( 'slug' ) for a single page.

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?

ProblemWhyFix
Plugin binds at load timeIt registers on whichever copy is global at that momentCheck the order in the page source
Caching and combiningConcatenation moves the inline snippet away from its fileExclude both files
Different versions in the adminThe condition must be front end onlyKeep it that way
Extra bytesA second library is roughly the size of the first againScope tightly, retire early
SecurityOld versions have known weaknessesNever 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 catches this kind of debt before it grows, and our 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.

FAQ

Questions people ask

11 answers. Can't find yours? Ask an engineer.

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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer
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.

Link to this answer

Keep reading

Want an engineer on it?

Tell us what is wrong in plain words. A person reads it, today.