Languages on Subdomains and Separate Domains
On this page
By default each language lives in a folder of your site: example.com/pl/about/. You can instead give
every language its own subdomain (pl.example.com/about/) or its own domain
(example.pl/about/). The page itself, its translation and its address after the host are the same
in every mode – only the host changes.
Available in the free version (version 2.7.0 and later).
#Which one to choose
| Directory | Subdomain | Separate domain | |
|---|---|---|---|
| Example | example.com/pl/ |
pl.example.com |
example.pl |
| DNS and SSL work | none | one record per language (or a wildcard) and a certificate that covers them | a domain per language, each with its own DNS and certificate |
| Login on the language’s address | yes | only with one wp-config.php line (see below) |
never |
| Shopping cart carries over between languages | yes | with the COOKIE_DOMAIN line; otherwise through the language switcher |
yes, through the language switcher |
If you have no strong reason, stay with Directory: it needs nothing outside WordPress and has no
limitations. Choose subdomains or domains when a language needs to look like a site of its own – a
local domain for a local market, for example.
The default language always stays on your site’s own address (Settings → General → Site Address).
The admin, the login page and background requests stay on it too, in every mode. Whatever you set
here changes how visitors see the site, not where you work on it.
#What you must prepare outside WordPress
WordPress cannot do this part for you, and most problems come from here:
- DNS. Every language host must point at the server your site runs on – one record per
subdomain, or a wildcard record (*.example.com). A separate domain needs its own records. - An SSL certificate that covers every host. A wildcard certificate covers all subdomains; with
separate domains each one needs a certificate of its own. - The host must reach your WordPress. On most hosting this means adding the subdomain or
domain as an alias of your site in the hosting panel or the web server’s configuration. A host that
shows a different site, or a hosting default page, will not work.
#Turning it on
- Go to LATW Multilingual → Settings → Languages.
- In Global options, under Language in URL, pick Subdomain or Separate domain per
language. - For subdomains, the hosts are built for you from the URL prefix of each language
(pl→pl.example.com; a leadingwww.is dropped). For separate domains, fill in the
Domain column for every active language – just the host name,example.pl. A pasted
https://example.pl/is cleaned up. - Click Check domains. It requests your site through each host and tells you, per host, whether
it works, has no DNS record, has a certificate error, or answers with some other site. You can run
it before saving. - Save. The new addresses work immediately.
If Separate domain per language is selected while an active language has no domain, the rest of
your settings are saved but the previous mode stays – so the site keeps working while you finish the
form.
Check domains does not stop you from saving a host that fails. Hosts that are still propagating or
that only exist on a development machine are legitimate; the check tells you, it does not forbid.
#Changing the mode on a live site
The old addresses keep working: a visitor, a bookmark or a search result that uses
example.com/pl/about/ is redirected (permanently, 301) to pl.example.com/about/, and the other
way round when you go back to Directory – as long as the host still points at your site. Search
engines follow these redirects, but expect the usual re-indexing period after any change of address.
In Search Console, add every new host as a property, from the same Google account.
#Logging in, the admin bar and editing
- Subdomains. Your login belongs to one host. To be logged in on the language subdomains too (and
see the admin bar there), add this line towp-config.php, above “That’s all, stop editing!”:
define( 'COOKIE_DOMAIN', '.example.com' );. The Languages tab shows the exact line for your site.
Everyone is logged out once after the change. - Separate domains. Browsers do not share a login between different domains, so you are never
logged in on a language’s domain and there is no admin bar. This is a limit of the web, not of the
plugin. - Page builders (Divi, Beaver Builder, Bricks, Oxygen). The visual editor always opens on your main
address, because that is where you are logged in. The page shows in the language you are
translating anyway. - Previews and “View” links. Every preview – in the page builders and in the standard block
editor – stays on the main address, where you are logged in, so it shows your unsaved changes. A
“View” link opens a translation on its own host and shows it as a visitor sees it – not logged in.
#Shopping cart (WooCommerce)
A cart is tied to the address it was made on, so with each language on its own host a cart would stay
behind when a customer switched language. To prevent that, the plugin carries the cart along when the
customer uses the language switcher (or any link to another language’s host on your own pages):
the items and any coupons arrive in the other language’s cart, and the customer lands on the same page
there. Prices, stock and availability are checked again on arrival, so an item that has meanwhile sold
out is reported instead of added. Pages, the cart’s AJAX updates and the order confirmation page all stay on the customer’s
language host.
What it will not do:
- It only works through links on your site. A customer who reaches another language by a bookmark or
a search result starts with an empty cart there, as no switch happened. - It carries the items and coupons, not the customer: the billing address, email and login stay where
they were entered. - It does not carry data that other plugins attach to a cart item (a custom text field on a product,
for example). The product itself arrives; that extra data does not. - The last cart wins: switching to a language replaces the cart that host held before.
Nothing is needed from you, and nothing changes in the cached page: links stay as they are, and the
carrying happens when the customer clicks. With subdomains and the COOKIE_DOMAIN line above, the
cart is shared by the browser already and none of this is used.
A payment gateway that calls your shop in the background (a payment notification, a webhook) reaches the
main address, not a language host, so such a request is handled in your default language. The order
itself keeps the language the customer ordered in.
#Search engines and sitemaps
hreflang and canonical tags point at the right host for each language automatically. The sitemap
stays on your main address and lists every language’s address with its alternates; the robots.txt
of every language host points crawlers to that one sitemap. Google only
accepts addresses from other hosts when all hosts are verified in Search Console under the same
account – do that once for each subdomain or domain.
#Page caching
A page-caching plugin stores each page under the address it was requested on, so a page on
pl.example.com and the same page on example.com are cached separately and a visitor never gets
the wrong language from the cache. Nothing needs to be set up for this. We checked it with WP Super
Cache; other caching plugins that keep a separate copy per host behave the same way.
Cached pages hold the language switcher and the hreflang and canonical tags, so they have to be
rebuilt when the addresses change. Saving LATW Multilingual → Settings → Languages therefore
empties the page cache of WP Super Cache, WP Rocket, W3 Total Cache, LiteSpeed Cache, SiteGround
Optimizer, Cache Enabler and WP Fastest Cache. With any other caching plugin, or a cache on the
server or in a CDN (Cloudflare, for example), clear it yourself after changing the mode or adding a
language. Until you do, visitors may still be shown the old addresses.
If you use a CDN or a server cache, make sure it keeps a separate copy per host – this is the default
for most, but a rule that ignores the host would serve one language’s page on another’s address.
#Visitors’ language choice
With subdomains, the language a visitor picks is remembered across all of them. With separate
domains a browser cannot share it, so Browser auto-detection works on the first visit to your
main address only; after that, the language host the visitor is on decides.
#What this does not do
- It does not set up DNS, certificates or your hosting – see What you must prepare outside
WordPress. - It does not log you in across different domains.
- It does not give the default language a domain of its own: it stays on your site’s address.
- It is not available on a multisite network.
- It does not make a host that points somewhere else work: a visitor on a subdomain you have not
enabled is sent to the main address, but a different name that merely points at the same server
(a hosting alias, a staging domain) is left alone.
#Developer reference
Filters and constants:
| Name | Purpose |
|---|---|
latwm_url_mode (filter) |
Overrides the mode: directory, subdomain or domain. Also the way out if bad DNS takes the language hosts down. The mode is read early, so add the filter in a must-use plugin – one in a theme’s functions.php is too late. |
LATWM_URL_MODE (constant) |
Same, from wp-config.php. |
latwm_url (filter) |
The final URL built for a language (unchanged). |
latwm_detected_lang (filter) |
The language detected for the request (unchanged). |
latwm_legacy_url_redirects (filter, default true) |
Return false to switch off the 301s from the previous mode’s addresses. |
latwm_allow_domain_urls_on_multisite (filter, default false) |
Return true to allow the host modes on multisite, at your own risk. |
latwm_cart_handoff (filter, default true) |
Return false to switch off carrying the cart to another language host. |
latwm_flush_page_caches (action) |
Fires after the plugin has emptied the page caches it knows: on saving the Languages tab, and at the end of a request that translated a page into a language for the first time, switched a translation on or off, or changed a translation shown on many pages (menus, strings, forms, categories, header and footer templates). Hook your own cache’s purge here. |
When the mode is changed by the constant or the filter, the permalink rules are rebuilt automatically
on the next request; you do not need to save the permalinks again.
latwm_url_strategy() returns the object that knows where a language lives in an address:
lang_from_request(), lang_from_url( $url ), url_for_lang( $url, $lang ), lang_home( $lang ),
hosts(), is_site_host( $host ). latwm_get_url( $lang, $url ) keeps working in every mode.
In the host modes, content_url, plugins_url, theme_root_uri, includes_url, rest_url,
upload_dir, the URLs of enqueued styles and scripts, and the admin-ajax.php URL are rewritten to the language host on the front end, so
that fonts and AJAX requests are not cross-origin. Addresses on any other host (a CDN) are not touched.