Skip Navigation
Updated
May 2, 2022

This tutorial explains how to set up languages in different domains (or subdomains) in a multisite install. Please read carefully, as you will need to replace a file to complete the setup.

WPML offers support for setting up WPML to use a different domain per language when using WordPress in the multisite mode. This can only be accomplished by using a drop-in plugin.

A drop-in plugin differs from regular plugins in that this one will load earlier in the WordPress execution, before the URL is resolved to a specific site. sunrise.php is a drop-in and it works by being placed in the wp-content folder and enabling it in wp-config.php.

Setting this up is a two-step process described below.

Step 1: Install drop-in sunrise.php

When you already have the file sunrise.php in the wp-content folder

  1. Append content of the sunrise.php file from WPML’s WPML_DIR/inc/tools/ folder to your wp-content/sunrise.php file. Make sure it will be executed (e.g. will not be placed after a return statement).
  2. Make sure that you have the line below in your wp-config.php file:
    define('SUNRISE', 'on');

    If you need to change the value to on, make sure that you don’t enable functionality that you do not want in your existing (but inactive) sunrise.php file.

When you do not have the file sunrise.php in the wp-content folder

  1. Copy the sunrise.php file from WPML’s WPML_DIR/inc/tools/ folder to your wp-content folder.
  2. Add the line below in wp-config.php
    define('SUNRISE', 'on');

Step 2: Set up the domains

First, make sure that your domains have the correct DNS set and they point to the same folder as the domain of the default language.
Under WPMLLanguagesLanguage URL format select A different domain per language, fill in the corresponding URLs, and then click Apply.

Using a different domain per language
Using a different domain per language

If you get an error message (Data not saved), try saving again with the Validate on save boxes unchecked.

The sunrise.php file can be obtained from the Sitepress Multilingual CMS plugin: inc/tools/sunrise.php

How it works

The sunrise.php drop-in filters the query that WordPress uses for resolving the domain used in the URL of the request and compares it to the list of associated domains of each site installed. It does this by checking each site until it finds a match. The domains used for the secondary languages are not present in the wp_blogs or wp_site tables but rather in the icl_sitepress_settings value in wp_options for each site.

A drop-in was required because this happens before the plugins_loaded hook is fired and before any regular plugin can add any filter or perform any actions.

Apache and DNS settings

Besides setting the sunrise.php file, as described in this tutorial, you should also create the DNS entries for all domains and point them all to the same WordPress install. For instructions, follow this tutorial on setting up domains per language.

Debugging

  • Make sure that the drop-in script is being loaded and executed. e.g. WPML_SUNRISE_MULTISITE_DOMAINS is defined.
  • Check if another drop-in plugin is preventing execution of the one indicated here.
  • Make sure that you’ve set up the DNS to point all domains to your multisite WordPress install.
  • Make sure that you’ve set up Apache (or your web server) to respond to all domains for your multisite WordPress install.
  • For issues with your language switcher, make sure to install our WPML-MU-Domain-Mapping bridge plugin.