Created
October 17, 2012 10:40
-
-
Save kovshenin/3904905 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Language Redirect | |
*/ | |
add_action( 'init', 'language_redirect_init' ) { | |
// Map language to blog id | |
$sites = array( | |
'default' => 1, | |
'en' => 2, | |
'de' => 2, | |
); | |
$lang = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 ); | |
$id = array_key_exists( $lang, $sites ) ? $sites[ $lang ] : $sites['default']; | |
if ( get_current_blog_id() != $id ) { | |
wp_redirect( get_blogaddress_by_id( $id ) ); | |
die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment