Fix “Google Maps JavaScript API multiple times” in WordPress
Google's instructions are short: include the Maps loader once per page. On WordPress it's easy to end up with two or three, because the theme, the page builder and every plugin with a map or address field can each add their own. The result ranges from a harmless warning to a map that loads and then goes blank.
How to tell this is your problem
- The console warns that the API was included more than once.
- The map appears for a moment, then goes blank or grey.
- Markers, info windows or address autocomplete stop responding, while the map itself still shows.
- Errors such as google.maps.X is not a constructor or Cannot read properties of undefined appear in a plugin's script file.
- Different Maps errors appear on the same page, for example RefererNotAllowedMapError alongside a working map, because each loader carries a different key.
This is the warning Google prints:
Why it happens
WordPress plugins add scripts with wp_enqueue_script(). Two plugins that both need Maps rarely know about each other, so each enqueues its own copy of https://maps.googleapis.com/maps/api/js under its own handle. WordPress only de-duplicates scripts that share a handle, so both tags reach the page.
The Maps JavaScript API isn't designed to be initialised twice in one document. The second copy can redefine the google.maps namespace after the first plugin has already built its map, or load with different libraries, a different version or a different key. What breaks depends on load order, which is why the symptoms can change from one page load to the next.
The usual pairs that collide:
- A theme or page builder map widget plus a dedicated maps plugin.
- A maps plugin plus a form plugin that adds Places autocomplete to an address field.
- A store locator or directory plugin plus the theme's own contact-page map.
- A plugin that loads Maps on every page, even pages with no map, plus a widget that loads it again where a map exists.
- Hand-added code in the theme's functions.php or a header-scripts plugin, left over from an earlier set-up.
The fix, step by step
- 01Open the affected page, open developer tools and go to the Network tab. Reload, then type maps/api/js in the filter box. Count the requests. More than one means a duplicate.
- 02For each request, look at the Initiator column. It points to the script or HTML line that added the loader. Paths containing /wp-content/plugins/plugin-name/ or /wp-content/themes/theme-name/ tell you who is responsible.
- 03Compare the query strings. Note the key, libraries, v and callback values on each. You need to keep a loader that includes every library the page uses, for example places if a form has address autocomplete.
- 04Look in each plugin's settings for an option such as "Load Google Maps API", "Do not load Maps script" or "Maps API already loaded by theme". Most mature maps plugins have one. Turn it off on all but one plugin.
- 05If there is no such option, dequeue the extra script in a small snippet or child theme (see below).
- 06If you can't tell which plugin to keep, keep the one that renders the visible map and make sure its loader requests the libraries the other plugin needs.
- 07Clear any caching or script-optimisation plugin, then reload. Combining and deferring plugins can reorder loaders, so test with optimisation on and off.
Dequeue the duplicate in code
Find the handle the second plugin uses. View source, find the duplicate <script> tag and read its id attribute. WordPress sets it to handle-js. Then remove it with a late priority so the plugin has already enqueued it:
add_action( 'wp_enqueue_scripts', function () {
// Handle taken from the duplicate tag's id, minus the "-js" suffix.
wp_dequeue_script( 'other-plugin-google-maps' );
wp_deregister_script( 'other-plugin-google-maps' );
}, 100 );
Only do this if the plugin's own map code can run against the remaining loader. If that plugin's script lists the Maps handle as a dependency, deregistering it can stop the plugin's script from loading too. In that case, re-register the handle pointing at the same URL as the loader you kept, or switch the plugin's map feature off.
If you load Maps in your own code
Google's dynamic library import (the inline bootstrap loader plus google.maps.importLibrary()) protects the page from loading the API more than once. If your theme code uses it, other scripts can call importLibrary() for the libraries they need without adding another script tag. See moving to the async loader.
If you must use a direct script tag, check for an existing loader first, for example by checking whether window.google?.maps already exists before adding your own.
Confirm it is fixed
Reload the page in a private window. The network tab should show exactly one maps/api/js request and the console warning should be gone. Click a marker, open an info window and try any address field to make sure the plugin you disabled isn't now missing a library.
Then run a scan. It loads the page from a clean session and records the console errors and warnings it sees, including this one, so you can check pages you didn't test by hand.
Common questions
Is the “multiple times” warning harmful if the map still works?
It can be. Load order can change with caching, network speed or a plugin update, and a page that works today can break tomorrow. It also means the browser downloads the API twice, which slows the page.
Can I just remove one of the plugins?
Yes, if you don't need it. If both are needed, keep one loader and switch off map loading in the other, making sure the remaining loader includes every library both plugins use.
Why does the duplicate only appear on some pages?
Many plugins only enqueue the loader on pages that contain their shortcode or block. The duplicate only happens where both plugins' content appears on the same page.
Will a script optimisation plugin fix it?
No. Combining or deferring scripts doesn't remove the second loader, and it can change which copy runs first, which sometimes makes the symptoms worse.
A scan tells you in about twelve seconds, from a clean session.