WPML switch backend language on language switch
Since wp 4.7 the backend language is changed by changing the language in your userprofile. Using WPML, if you change the site language or post-, page language, the backend language is not changing. The code below changes the site language when changing the wpml language selector.
add_action('init', 'vh39hcr9_wpml_switch_user_lang', 20); function vh39hcr9_wpml_switch_user_lang() { $languages = apply_filters( 'wpml_active_languages', NULL ); foreach($languages as $l) { if ($l['active']) { $locale = $l['default_locale']; break; } } switch_to_locale( $locale ); }
On init get the active wpml locale and set the site locale. Effect: backend in the same language.
From wp 4.7
The above works for wp 4.0, since wp 4.7 the language is set in the userprofile. Rather than setting the user profile we clear the language setting in the userprofile, this way the site language determines the output.
add_action('init', 'vh39hcr9_wpml_switch_user_lang', 20); function vh39hcr9_wpml_switch_user_lang() { $user_id = get_current_user_id(); update_user_meta( $user_id, 'locale', null ); $languages = apply_filters( 'wpml_active_languages', NULL ); foreach($languages as $l) { if ($l['active']) { $locale = $l['default_locale']; break; } } switch_to_locale( $locale ); }