LocaleReady
Menu

Docs

Language switcher

Placing a language switcher as a block, a shortcode, a menu item, or a template tag.

The switcher is one set of language links, rendered four different ways depending on where your theme needs it. Whichever way you place it, it shows the same languages, in the same order, styled by the same settings, there is exactly one answer to “what does the switcher look like.”

Defaults

Set these once on the Visitors tab under LocaleReady → Settings, with a live preview beside the controls so you can see the result before saving:

  • Layout, a plain list of links, a dropdown that opens on click, or a compact <select>. Both the dropdown and the select layout ship as a real list of links first and are only turned into their interactive form by a small script, a visitor without JavaScript, or a search engine, still gets every language.
  • Language names, in their own language (“Español”), in English (“Spanish”), both (“Español (Spanish)”), or by code (“ES”).
  • Hide the current language. Off by default; some designs prefer to show only the languages a visitor could switch to.

Any placement below can override these defaults for itself.

Four ways to place it

Block. Insert the Language Switcher block in the block editor or the site editor, or paste <!-- wp:localeready/switcher /--> into the code editor.

Shortcode. [localeready_switcher] anywhere a shortcode runs, a post, a widget, a page builder’s shortcode element. Override one placement’s own settings with attributes: [localeready_switcher layout="dropdown" labels="both" hide_current="true"].

Classic menu. Under Appearance → Menus, find Language Switcher in the left-hand column and add it to a menu like any other menu item, for classic (non-block) themes.

Theme template. <?php localeready_switcher(); ?> in a PHP template file, for a classic theme’s header or footer.

What it does not show

A switcher renders nothing on a page where only one language applies, a page an exclusion rule hides the switcher on, or a site with only one language enabled. A language that would 404 for the current page (because a rule excludes it, or because a per-page setting turns it off) is left out of that page’s switcher rather than shown as a dead link.

Browser-language redirect

Also on the Visitors tab: send a first-time visitor to the language their browser is asking for, automatically, the first time they land on the site. A visitor who has already picked a language (by using the switcher, or by arriving at a language’s own URL) is never second-guessed after that, and search engine crawlers are never redirected.

Building a custom switcher

If you need something the four built-in placements do not offer, a switcher inside a React component, say, localeready_get_language_links() returns the same language links the built-in renderer uses, without any markup around them. See template tags for its signature.