Add-on for Mercator on WordPress multisite. It rewrites the HTML output so internal URLs (network domain, subsite URLs, uploads, plugins, themes, DNS prefetch, etc.) use the mapped public domains instead of the original multisite domains.
Mercator maps domains to sites; this plugin makes sure the front-end output consistently reflects those mappings—including variants used in JavaScript (https:\/\/…), protocol-relative URLs (//…), and URL-encoded strings.
The plugin does nothing if Mercator is unavailable or if $GLOBALS['mercator_current_mapping'] is not set in context.
- On
init, it builds a map of source URLs → mapped URLs for the current network and for sites returned byWP_Site_Query(public sites by default). - It starts an output buffer callback that runs
str_replaceover the full response for each pair, including escaped and encoded forms.
Note: This is a full-page string replacement. Use it in environments where that trade-off is acceptable.
- Replaces subsite internal URLs with Mercator
mangle_url()results for active mappings. - Aligns network-level URLs (uploads, plugins, parent and child theme URIs, DNS prefetch host) with the mapped domain when the main site differs from the mapped URL.
- Optional early pass on
init(priority0) for FacetWP AJAX refresh / autocomplete requests so URLs stay correct in those responses.
Filters the arguments passed to WP_Site_Query when collecting sites for replacement (default: public sites, ordered by ID, max 500).
add_filter( 'mercator.domain_replacement.site_query_args', function ( array $args ): array {
$args['number'] = 1000;
return $args;
} );- Install and activate Mercator according to its documentation.
- Install this plugin (ZIP upload, or clone into
wp-content/plugins/orwp-content/mu-plugins/). - Network activate if you use it as a normal plugin, or place the folder under
mu-pluginsif you run it as a must-use plugin.
Package: beapi/mercator-domain-replacements (type wordpress-muplugin). Point Composer’s installer to your MU-plugins directory, for example:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/BeAPI/mercator-domain-replacements"
}
],
"require": {
"beapi/mercator-domain-replacements": "^1.0"
},
"extra": {
"installer-paths": {
"wp-content/mu-plugins/{$name}/": ["type:wordpress-muplugin"]
}
}
}Adjust installer-paths to match your project layout.
Issues and pull requests are welcome on GitHub. Please describe steps to reproduce for bugs and, when possible, the multisite + mapping setup you use.
Made by Be API. This plugin is maintained on a best-effort basis; we do not guarantee free support. If it helps your project, you can support us.
GPL-3.0-or-later. See LICENSE.
- Changed: minimum PHP version is 8.0
- Docs: README refresh (requirements, hooks, installation)
- Fixed: support mapping for encoded URLs
- Fixed: mapping network private domain
- Fixed: handle parent theme URLs
- Fixed: URLs on FacetWP refresh
- Add filter to modify site query args
- Fixed: URL fixes (notably Polylang /
sitemap.xml)
- Fixed: mapped upload path
- Add mapped plugin and theme paths
- Change DNS-prefetch path
- Fixed: use active mapped domain for the current subsite only (not the network domain)
