Multisite use language code as subdirectory

Here’s a proper multisite solution: Install WordPress directly on the root of your domain mysite.de. After that, setup a multisite and chose the subdomain option (Yes, subdomain! It’s far more flexible and you can use it with subdirectories as well). WordPress will ask you to update wp-config.php and .htaccess. To the wp-config.php add the following … Read more

Multilingual theme: Changing locale based on URL

My problem here is that get_query_var(‘language’) isn’t defined in the function set_my_locale Because get_locale (which applies the filter locale) is called before wp() (which parses the query & sets up the variables). You’ll have to manually inspect the request yourself: if ( strpos( $_SERVER[‘REQUEST_URI’], ‘/de/’ ) === 0 ) { // German } else { … Read more

How to change language file used by _e function

Actually you need to hook in the ‘locale’ filter to set the language you want: add_filter(‘locale’, function($locale) { return esc_attr($_GET[‘language’]); }); Then in the links of your switch, you need to pass the language variable: <a href=”https://wordpress.stackexchange.com/questions/260015/<?php echo add_query_arg(“language’, ‘xx_XX’) ?>”>XX</a> Where xx_XX is the language locale code for language XX