Are there any alternative approaches or plugins recommended for implementing automatic language redirects in WordPress websites?
One alternative approach for implementing automatic language redirects in WordPress websites is to use the Polylang plugin. This plugin allows you to create multilingual websites and easily set up language redirects based on the user's preferred language or browser settings.
// Redirect users to the appropriate language version of the site
function language_redirect() {
if (function_exists('pll_current_language')) {
$current_language = pll_current_language();
if ($current_language == 'en') {
wp_redirect('https://example.com/en/');
exit;
} elseif ($current_language == 'fr') {
wp_redirect('https://example.com/fr/');
exit;
}
}
}
add_action('template_redirect', 'language_redirect');