I am trying to load localization file depends on users settings. Is this way is correct or there are better ways to implement locale changing depends on user settings?

           add_filter( 'locale', 'theme_localized' );

            function theme_localized( )
                if(is_user_logged_in()) {
                    $locale = get_user_locale();
                     return $locale;


This code is working but I am not sure that this is the conventional way of translating website.

1 Answer 1


By default WordPress only loads translations according to the user's language when they're viewing admin pages.

You can see that in the code for the load_theme_textdomain function:

$locale = apply_filters( 'theme_locale',
    is_admin() ? get_user_locale() : get_locale(),
//  ^^^^^^^^
$domain );

So your code is fine if you want to override that behaviour for the front end of your site.

Is it conventional? Well, this is what filters are for. However, I'd say this isn't normally done unless the language of the actual content is also changing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.