Language Switcher -

I’ve created a language switcher as a dropdown and im wondering if there is a way to output the available languages in a way so that the current language is always on first position.

1 Like

You would need to use a cookie I think, to keep track of the selection across pages. Then read the cookie value back with PHP or javascript to sort the list. Try searching the forum, im sure theres been some similar questions on this in the past.

Without the links and the html. tags etc., but this should work:

// $site->language() returns the current language
$currentLang = $site->language()->code();
echo $currentLang;
foreach($site->languages() as $l) {
  if($l->code() === $currentLang) continue;
  echo $l->code();

Use name() instead of code if you want to use the language name instead of the language code.


Thanks, that helped a lot.