A WordPress Multisite with Google blocked: before, half-fixed, fixed

A three-site test Multisite (International, US, Germany) with a small theme written to behave like the problem in the job post. Google's hosts are blocked in the test browser: jQuery fails, Maps hangs for 30 seconds and Tag Manager for 45 seconds.

This is a simulation, not a test from inside China, and not your theme. The company and content are fictional. It doesn't include WPML, Gravity Forms, Turnstile or Complianz.

As reported

The script stops at jQuery is not defined, so every section below the heading stays hidden. The load event took about 46 seconds.

8 seconds after opening, before any fix
8 seconds after opening, before any fix

Swapping the jQuery source isn't always enough

WordPress's own jQuery runs in noConflict mode. If the theme uses a global $, the error becomes $ is not a function and the page is still blank.

jQuery now loads locally, but the script still fails
jQuery now loads locally, but the script still fails

Fixed

Sections, menu and location pop-up work while Google is still blocked. The load event took about 1 second. The contact page shows a local map image.

Home page with all five fixes, Google still blocked
Home page with all five fixes, Google still blocked
Contact page with all five fixes: local map image
Contact page with all five fixes: local map image

The five changes

Each one is a separate snippet that can be switched off without touching the theme files.

Load jQuery from your own server
<?php
// Use WordPress's own jQuery instead of Google's copy. Undo: remove this snippet.
add_action( 'wp_enqueue_scripts', function () {
	wp_deregister_script( 'jquery' );
	wp_register_script( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), null, true );
}, 100 );
Keep the global $ that older theme code expects
<?php
// WordPress's jQuery runs in noConflict mode. Give older theme code its global $ back.
// Undo: remove this snippet.
add_action( 'wp_enqueue_scripts', function () {
	wp_add_inline_script( 'jquery-core', 'window.$ = window.$ || window.jQuery;' );
}, 101 );
Show content even if the animation script never starts
<?php
// If the animation script has not started after 3 seconds, show the content anyway.
// Undo: remove this snippet.
add_action( 'wp_head', function () {
	echo "<style>html.aos-failed [data-aos]{opacity:1!important;transform:none!important}</style>\n";
	echo "<noscript><style>[data-aos]{opacity:1!important;transform:none!important}</style></noscript>\n";
	echo "<script>setTimeout(function(){if(!document.querySelector('.aos-init'))document.documentElement.className+=' aos-failed'},3000)</script>\n";
}, 99 );
Maps on the contact page only, with a static fallback
<?php
// Load Maps only on the contact page, without blocking it, with a local static image as fallback.
// Undo: remove this snippet.
add_action( 'wp_enqueue_scripts', function () {
	wp_dequeue_script( 'google-maps' );
	if ( ! is_page( 'contact' ) ) {
		return;
	}
	$img = esc_url( home_url( '/wp-content/themes/sample-device/map-fallback.svg' ) );
	$js  = <<<JS
(function () {
  var m = document.getElementById('map');
  if (!m) return;
  m.innerHTML = '<img src="$img" alt="Map showing our office location">';
  window.sampleMapReady = function () {
    m.innerHTML = '';
    new google.maps.Map(m, { zoom: 12, center: { lat: 51, lng: 0 } });
  };
  window.addEventListener('load', function () {
    var s = document.createElement('script');
    s.async = true;
    s.src = 'https://maps.googleapis.com/maps/api/js?key=DEMO&loading=async&callback=sampleMapReady';
    document.head.appendChild(s);
  });
})();
JS;
	wp_add_inline_script( 'theme-main', $js );
}, 100 );
Start GTM after the page has loaded
<?php
// Start GTM after the page has loaded, so a blocked request cannot hold the load event.
// On a live site, check this against Complianz consent rules and tags that must fire early.
// Undo: remove this snippet.
add_action( 'after_setup_theme', function () {
	remove_action( 'wp_head', 'sample_theme_gtm', 1 );
	add_action( 'wp_head', function () {
		echo "<script>window.dataLayer=window.dataLayer||[];window.addEventListener('load',function(){setTimeout(function(){dataLayer.push({'gtm.start':Date.now(),event:'gtm.js'});var j=document.createElement('script');j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id=GTM-DEMO';document.head.appendChild(j)},0)});</script>\n";
	}, 1 );
}, 20 );

Results with Google blocked

All three sites, home and contact pages.

VersionSitePageSections visible after scrollingLoad eventMenuLocation pop-upMapConsole errors
As reportedInternationalhome0/446.0 sfailsfailsjQuery is not defined
As reportedInternationalcontact0/146.0 sfailsfailsempty boxjQuery is not defined
As reportedUShome0/446.0 sfailsfailsjQuery is not defined
As reportedUScontact0/146.0 sfailsfailsempty boxjQuery is not defined
As reportedGermanyhome0/446.0 sfailsfailsjQuery is not defined
As reportedGermanycontact0/145.9 sfailsfailsempty boxjQuery is not defined
jQuery source swapped, nothing elseInternationalhome0/446.0 sfailsfails$ is not a function
jQuery source swapped, nothing elseInternationalcontact0/146.0 sfailsfailsempty box$ is not a function
jQuery source swapped, nothing elseUShome0/446.0 sfailsfails$ is not a function
jQuery source swapped, nothing elseUScontact0/145.9 sfailsfailsempty box$ is not a function
jQuery source swapped, nothing elseGermanyhome0/446.1 sfailsfails$ is not a function
jQuery source swapped, nothing elseGermanycontact0/146.0 sfailsfailsempty box$ is not a function
All five fixesInternationalhome4/41.0 sworksworksnone
All five fixesInternationalcontact1/11.0 sworksworksstatic imagenone
All five fixesUShome4/41.0 sworksworksnone
All five fixesUScontact1/11.0 sworksworksstatic imagenone
All five fixesGermanyhome4/41.0 sworksworksnone
All five fixesGermanycontact1/11.0 sworksworksstatic imagenone

Not covered here: visitors who can reach Google (including the live map), Tag Manager tags and consent. On a real site those are tested on staging.