Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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','wpse72692_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';
}
share|improve this answer
    
Can this be added to my functions.php? –  hitautodestruct Nov 15 '12 at 17:50
    
No - it can only work as a plug-in. But that's not more difficult than using it in functions.php –  Stephen Harris Nov 15 '12 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? –  hitautodestruct Nov 15 '12 at 17:54
    
Yup, but with comment headers. Plugin class isn't necessary. See edit :) –  Stephen Harris Nov 15 '12 at 18:02

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');
}
share|improve this answer
    
won't this effect performance? –  hitautodestruct Nov 15 '12 at 17:55
    
nope =) (less that adding filter...) –  Oleg Butuzov Nov 15 '12 at 18:09
2  
I went for the plugin answer since this is slightly more hassle. For anybody else viewing, this answer also works. Thank You @CodeMonkey! –  hitautodestruct Nov 15 '12 at 18:12

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');
    }
}
share|improve this answer
    
so this would simply revert to english and then switch back when I enter the admin area? –  hitautodestruct Nov 17 '12 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 '12 at 11:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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