function redirect_based_on_language() { $language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); $currentUrl = home_url(); // Obtiene la URL base del sitio if ($language === 'en' && strpos($_SERVER['REQUEST_URI'], '/en') === false) { wp_redirect("$currentUrl/en"); exit(); } } add_action('template_redirect', 'redirect_based_on_language');