1

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.com/sp/about-us, load contents of https://website.com/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.com/sp/about-us to https://website.com/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.com/about-us?language=sp. Is there a way to pass this converted url to wordpress, without actually redirecting to this url?

0

I'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.com/<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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.