I have a wordpress website that has multiple translations, and i was trying to get the website to determine the language to load from the URL e.g. if its , load contents of , but in spanish.
I have tried something like this,
add_action('plugins_loaded', 'reroute_url');
function reroute_url(){
$languages = ['sp'];
$uri = $_SERVER['REQUEST_URI'];
$uri_components = explode("/", $uri);
$language = $uri_components[1];
if (!in_array($language, $languages)){
return;
}
$_SERVER['REQUEST_URI'] = substr($uri, 1 + strlen($language)).'?language='.$language;
}
basically converting to so then i can use this GET parameter to change the language, but this ended up with wordpress redirecting to . Is there a way to pass this converted url to wordpress, without actually redirecting to this url?
I have a wordpress website that has multiple translations, and i was trying to get the website to determine the language to load from the URL e.g. if its https://website/sp/about-us, load contents of https://website/about-us, but in spanish.
I have tried something like this,
add_action('plugins_loaded', 'reroute_url');
function reroute_url(){
$languages = ['sp'];
$uri = $_SERVER['REQUEST_URI'];
$uri_components = explode("/", $uri);
$language = $uri_components[1];
if (!in_array($language, $languages)){
return;
}
$_SERVER['REQUEST_URI'] = substr($uri, 1 + strlen($language)).'?language='.$language;
}
basically converting https://website/sp/about-us to https://website/about-us?language=sp so then i can use this GET parameter to change the language, but this ended up with wordpress redirecting to https://website/about-us?language=sp. Is there a way to pass this converted url to wordpress, without actually redirecting to this url?
Share Improve this question asked Jun 22, 2019 at 13:32 whynoworkwhynowork 111 bronze badge1 Answer
Reset to default 0I'm not sure if this is the "best" way to approach it but this is what I would try first.
I would create a taxonomy (like categories) called languages. Maybe even use categories (if they are not in use for something else). You can structure permalinks to go example/<cat-name>/<page-stub>
and, thus, have the language as part of the URL. I would imagine you can do the same for a custom taxonomy.
This would allow you to have separate archives for each language.
You can use register taxonomy to make a new category-like or tag-like taxonomy.