WPML

WPML lets you create virtual directories for all languages, including the default language. These are not real physical directories on the server’s drive, but virtual directories that only appear in URLs.

Please note that when the Use directory for default language option is set on the WPMLSettingsURLs and SEO page, you must choose what to show for the root URL: a redirect to the default language, an HTML file, or a WordPress page.

With language folders for all languages, your site’s structure can look like:

mysite.com/en/
mysite.com/es/
mysite.com/fr/

To enable this format, go to WPMLSettingsURLs and SEOUse directory for default language and scroll down to the Language URL format section.

Selecting the Use directory for default language option
Selecting the Use directory for default language option

What Is a Root Page and Do I Need One?

The root page of your website is the content that loads when visitors access your domain name, i.e. mysite.com, in a web browser. If you are using the Use directory for default language option, the starting page will be the same for all your visitors, regardless of the available languages on your site.

You don’t need a root page if you only want visitors to land on your default language. If the root URL setting asks for a page or a file, but you only want a redirect, choose Redirect to the default language (from WPML 5.3).

Below you can see a simple example of a root page, which features a welcome message and links to the site’s language versions.

A root page on the front-end
A root page on the front-end

Setting up the Root Page

In order to use a root page, you must first select the Different languages in directories option.

Then, enable the Use directory for default language option.

Now, you must choose what goes into your site’s root URL. For the root URL, you can choose between a redirect to the default language, an HTML file or a WordPress page.

Redirecting to the Default Language

From WPML 5.3, you can send visitors from your bare domain to your default language. For example, example.com goes to example.com/en/. You don’t need a page or an HTML file. Most sites need only this option.

Go to WPMLSettingsURLs and SEO. Under What to show for the root url, select Redirect to the default language and save.

This is a permanent (301) redirect. Browsers and caches remember it, so clear your site cache each time you change this setting.

  • Campaign links keep their parameters, such as utm_*, gclid or fbclid.
  • Other parameters stop the redirect. For example, a root URL with ?add-to-cart= shows your front page, so the action doesn’t run twice.
  • Uptime monitors that check your bare domain now get a 301. Point them at your default language home page, for example example.com/en/.

Hooks for Developers

wpml_root_redirect_status changes the redirect status. The default is 301. You can return 302, 303, 307 or 308.

Use a temporary redirect for the root URLPHP
add_filter( 'wpml_root_redirect_status', function( $status, $location ) {
    return 302;
}, 10, 2 );

wpml_root_redirect_tracking_parameters adds parameters that the redirect keeps. Parameters that start with utm_ are always kept. Names are case-sensitive.

Keep a custom tracking parameter on the root redirectPHP
add_filter( 'wpml_root_redirect_tracking_parameters', function( $names ) {
    $names[] = 'ref_id';
    return $names;
} );

Selecting an HTML File

When you choose an HTML file, you need to provide its path. If the path starts with a slash “/”, it is an absolute path on the server. Otherwise, it is relative to the WordPress directory.

Using a Relative Path

You can upload the HTML file you want to use for your root page using a FTP program and place it under your site’s WordPress directory as shown in the image below.

Uploading an HTML file to your WordPress directory
Uploading an HTML file to your WordPress directory

Once the file is uploaded, you can set its relative path, by simply specifying the file’s name. As an example, we set the file name to root-page.html.

Adding the path to the HTML file option
Adding the path to the HTML file option

Using an Absolute Path

If you want to use an absolute path on your server you can upload your HTML file in any of the site’s folders.

Uploading an HTML file to the directory
Uploading an HTML file to the directory

Once you upload the file, you can set its absolute path, for example /home/andres/root-page.html.

Selecting a WordPress Page

If in the Language URL format card of WPMLSettingsURLs and SEO you choose A page for What to show for the root url, save your settings first and then click the Create root page link.

Clicking on the link to create a root page
Clicking on the link to create a root page

This redirects you to the WordPress page editor interface.

Here, you can design how you want your site’s root, main landing page to look like. For example, you can choose to display a welcome message and provide a language selection interface.

An example of a root page
An example of a root page

Once you finish adding your content, save the page.

That’s it! When visitors come to your site, this page will be used as the root landing page.

There are two exceptions. If you show returning visitors the language they picked, visitors who picked a language before go to the home page in that language. If you redirect visitors by browser language, new visitors go to the home page in their browser language.

Editing an Existing Root Page

From WPML 5.3, your root page is listed in Pages when you view All languages, with the label Root page next to its title. It has no language, so its row shows no translation icons. In WPML 5.2 and older, the root page is not listed in Pages.

To edit your root page, go to WPMLSettingsURLs and SEO and, in the Language URL format card, click the Edit root page link next to A page.

Clicking the link to edit the root page
Clicking the link to edit the root page

From WPML 5.3, if the root page is in the Trash, the link next to A page reads Restore the root page. Click it to restore the page as a draft, publish the page, and then save the settings.

More in This Section

Written byAmir