Skip to content

Instantly share code, notes, and snippets.

@ryelle
Last active September 25, 2018 20:39
Show Gist options
  • Select an option

  • Save ryelle/4d0fd05f63d09c4dcaf224ccda11fd1e to your computer and use it in GitHub Desktop.

Select an option

Save ryelle/4d0fd05f63d09c4dcaf224ccda11fd1e to your computer and use it in GitHub Desktop.
Switch the language of the site based on a query param, ex: `site.com/wp-admin?l=en_GB`
<?php
/**
* Plugin: Quick Langauge Switcher
* Note, this only sets the site language, if your user has a user-specific language set, it won't change.
*/
// sv_SE, ja, ko_KR, ar, he_IL
function kdwan_switch_language( $locale ) {
if ( isset( $_GET['l'] ) ) {
return sanitize_key( $_GET['l'] );
}
return $locale;
}
add_filter( 'locale', 'kdwan_switch_language' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment