6

My wordpress blog is set up as de_DE. This means that my login page is also displayed in de_DE.

I would like to only have the login page in en_US.

So, How would I programmatically change a single page's language?

Note: I have WPML but I don't wish to use it, I only want to change one page on the whole site.

3 Answers 3

4

This will need to go in a plug-in, just put the following inside a file (login-languge.php) in wp-content/plugins/

/*
Plugin Name:  Log-in Language
Plugin URI:   http://wordpress.stackexchange.com/questions/72692/how-do-i-change-the-language-of-only-the-login-page
Description:  Changes the language for log-in/register screens only
Author:       Stephen Harris
Author URI:   http://stephenharris.info
Version:      1.0
License:      GNU GPL 2
*/
add_action('plugins_loaded', 'wpse72696_login_language_init');

function wpse72696_login_language_init(){
    if( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ){
        add_filter('locale', 'wpse72692_login_language',10);
    }
}

function wpse72692_login_language( $locale ){
    return 'en_US';
}
4
  • Can this be added to my functions.php? Nov 15, 2012 at 17:50
  • No - it can only work as a plug-in. But that's not more difficult than using it in functions.php Nov 15, 2012 at 17:50
  • @StephenHaris So I would just dump this into a my_plugin.php and place it in my plugins dir? Or do I have to create a whole plugin class and so forth? Nov 15, 2012 at 17:54
  • Yup, but with comment headers. Plugin class isn't necessary. See edit :) Nov 15, 2012 at 18:02
4

You can repalce define( 'WPLANG', 'de_DE'); in your wp-config.php by this code structuer.

if (basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)) == 'wp-login.php'){
    define( 'WPLANG',  'en_US');
} else {
    define( 'WPLANG',  'de_DE');
}
3
  • won't this effect performance? Nov 15, 2012 at 17:55
  • 1
    nope =) (less that adding filter...) Nov 15, 2012 at 18:09
  • 3
    I went for the plugin answer since this is slightly more hassle. For anybody else viewing, this answer also works. Thank You @CodeMonkey! Nov 15, 2012 at 18:12
1

Another way you can do this in your functions.php using unload_textdomain($domain)

add_action('init', 'remove_login_translation');
function remove_login_translation() {
    if( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
        unload_textdomain('default');
    }
}
2
  • so this would simply revert to english and then switch back when I enter the admin area? Nov 17, 2012 at 10:34
  • sure, this will unload the default translation only on the login pages, and translation will load normally on other pages, whether admin or front-end.
    – Ahmad M
    Nov 17, 2012 at 11:14

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.