The language switcher

1. Add a language switcher
1.1 Add a language switcher in the menus
1.2 Add a language switcher as a widget
1.3 Add a language switcher anywhere
2. Options
2.1 Displays as dropdown
2.2 Displays language names and displays flags
2.3 Force link to front page
2.4 Hide the current language
2.5 Hide languages with no translation
3. Customizing language names
4. Customizing flags
4.1 Use a flag from the predefined list
4.2 Use a custom flag
5. Order of languages

The purpose of the language switcher is to create links to the translations of your current page. By default, if the current page is untranslated, the language switcher links to the front page in the corresponding language.

Note: To avoid 404 errors, Polylang does not display a language on frontend if there is no published content (post or page) in that language. If there is no content in any language, then the language switcher does not appear at all.

1. Add a language switcher

1.1 Add a language switcher in the menus

You can include the Polylang language switcher in your menu. If you don’t see the language switcher metabox, check that it is not disabled in the screen options.

language-switcher-menus

1.2 Add a language switcher as a widget

Polylang provides a widget to display the language switcher.

language-switcher-widgets

1.3 Add a language switcher anywhere

You can include a language switcher anywhere in your site by using the PHP template tag pll_the_languages().

2. Options

By default the language switcher will display languages names only. You can easily change the configuration thanks to the available options.

2.1 Displays as dropdown

language-switcher-dropdown

If you choose this option for the widget, it is not possible to display flags due to limitations of the html language. It is possible to work around this limitation with javascript (not provided by Polylang). There is no such limitation when using this option in the menu.

2.2 Displays language names, displays flags

In the example below (with the Twenty Twelve theme), you can see the result when both settings have been checked for the menus and for the widget.

language-switcher-dropdown-and-menu

2.3 Forces link to front page

You have the possibility to always link to the front page in the corresponding language even if the current page is translated.

2.4 Hide the current language

Choose this option  to never display the current language. The example below displays what could be seen on the French front page.

language-switcher-hide-current-language

2.5 Hide languages with no translation

If, for example, the current English post is not translated in Spanish, the language switcher doesn’t display any link for Spanish.

3. Customizing language names

You can change the language name by modifying the full name of the language.

4. Customizing flags

4.1 Use a flag from the predefined list

You can choose your language flag among all the flags when creating or editing a language. This flag is used on both frontend and admin sides.

4.2 Use a custom flag

It is possible to use your own images as flags. You have to use PNG or JPG files and name them with the WordPress locale. For example, en_GB.png. Then upload this file in the /wp-content/polylang/ directory (create the directory if it does not exist). Don’t use the /polylang/flags/ directory as your file would be removed when automatically updating the plugin.

Once the custom flag is uploaded, go in Languages > Settings > URL modifications module then click on save changes. Note that your custom flags are not used on admin side.

5. Order of languages

You can choose the order of the languages in the language switcher when creating or editing a language.