I want to change the language of my WordPress installation based on a choice the user can make in his profile (dropdown menu).
As I want to change frontend (prepared .mo files for the theme) and backend language I thought I could change the $locale
variable and it would work out.
So I came up with the following code in my functions.php
but that won´t do the job:
function change_lang() { get_currentuserinfo(); $lang = get_user_meta($current_user->ID, 'user_lang'); $locale = $lang[0]; return $locale; } add_filter('locale', 'change_lang');
When I return the value of $locale
, WP returns a simple NULL
, nothing more. When I release the hook, the defined value from WP_LANG()
is returned.
So, I am obviously wrong somewhere, but I can´t find where. Any hints?
Besides: I read this for inspiration and code, but I don´t want to have it as a plugin if possible.
Thanks in advance!
Edit: Fixed my code, but still no language change happens.