Knowledge BaseHreflang Manager › Setup

Add a Locale Selector to Your Site

The locale selector is a widget that allows users to switch between the different language, script, and country versions of the current page.

The plugin offers multiple implementation options for the locale selector. Let’s see what they are.

Automatic Locale Selector in Content

This implementation method allows you to automatically add the locale selector in the content of the page. The locale selector will be added at the beginning or the end of the content of the page.

To enable this feature, follow this procedure:

  1. Visit the Hreflang Options menu
  2. Open the Locale Selector tab
  3. Activate the Automatic Insertion Status toggle
  4. Use the Position option to set the position of the locale selector in the content of the page. The available options are “Beginning” and “End”.
  5. Use the Target Post Types option to set the post types where the locale selector should be added.

Add the Locale Selector in the Theme

This implementation method allows you to add the locale selector in the theme of your website. The locale selector will be added in any place of the theme where you call the da_hm_locale_selector() function.

To enable this feature, follow this procedure:

  1. Edit the theme file where you want to add the locale selector
  2. Add the following code where you want to add the locale selector: <?php da_hm_locale_selector(); ?>

Add the Locale Selector with a Shortcode

This implementation method allows you to add the locale selector in the content of the page using a shortcode. The locale selector will be added in any place of the content where you call the [da-hm-locale-selector] shortcode.

To enable this feature, follow this procedure:

  1. Edit a post or a page
  2. Add the following shortcode where you want to add the locale selector: [da-hm-locale-selector]

Add the Locale Selector Using the Dedicated Block

This implementation method allows you to add the locale selector in the content of the post or in a template file via the site editor, using a dedicated block. The locale selector will be added in any place of the content where you call the “Locale Selector” block.

To enable this feature, follow this procedure:

  1. Edit a post (e.g.: Posts → Add New) or a template (e.g. Appearance → Editor) using the site editor
  2. Click on the Add Block button
  3. Search for the “Locale Selector” block
  4. Click on the “Locale Selector” block to add it in the content of the page
  5. Update the post or page
  6. Visit the front end of the post or page to see the locale selector in action

Using Flags in the Locale Selector

This feature of the plugin enables the display of flags alongside textual content in the locale selector. Flags provide a visual cue to users about the alternate page they are selecting.

Enabling Flags

Flags are displayed when the Display Flags option is enabled in the plugin settings.

Applicable Display Styles

Flags are shown only with the following display styles:

  • Dropdown Menu
  • Modal Selector
  • List of Links

Primary Display Logic

If a locale code is present (e.g., en-USit-CH), the corresponding country flag is shown.

- Example: `EN-US` → United States flag
- Example: `IT-CH` → Switzerland flag

Secondary Display Logic

If only a language code is present without a country code (e.g., enit), the flag is determined using a language-to-country default mapping table. This table maps language codes to the most appropriate country flags. Note that this mapping is based on known relations between languages and countries. It is not exhaustive and may not cover all cases. Please note that the site administrator can override this mapping based on their preferences, please see the section below for details.

- Example: `EN` → United Kingdom Flag (default mapping for English)
- Example: `IT` → Italian Flag (default mapping for Italian)

Customizing Flag Mappings

Plugin users can override or modify the default language-to-country mapping via the Advanced -> Flag Overrides option. This option accepts comma-separated entries to adjust mappings as desired.

Format example:

en=us, fr=ca

This example sets the English language code (en) to show the United States Flag, and the fr language code to show the Canadian flag.

Text Labels are Always Displayed

Regardless of the flag display, the locale selector always includes a text label with information on the language, script, and locale of the page. Flags never replace text, they only supplement it visually.