• Hi,

    is there a way to apend url parameters like ?lang=en to the english version of a website?

    We need to redirect some pages to another website and somehow need to send information which language the user is coming from.

    Thanks for your help!
    Daniel

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chouby

    (@chouby)

    Hello,

    By default the language code is stored as /en/ in the url. The only situation where Polylang uses a query string ?lang=en is when WordPress is set to use plain permalinks but that would mean using ugly permalinks everywhere.

    If you don’t mind digging in PHP, here is the function that we use to get the language code from the url when using pretty permalinks as you do: https://github.com/polylang/polylang/blob/3.1/include/links-directory.php#L121-L133

    Thread Starter Daniel Letschka

    (@dinonid)

    Hello!

    Thank you!

    I don’t mind digging in PHP a bit, however I’m not sure how we could use this function to communicate the set language to another website.

    So when someone clicks lets say on “https://biocache.biodiversityatlas.at/explore/your-area” (this is a link on the homepage) – this page needs to know which language the user is coming from.

    Thanks again for your help,
    Best regards,
    Daniel

    Plugin Author Chouby

    (@chouby)

    It depends if you have access to the code of the other site which could read the language in the url.

    Another way could be to change the Polylang links model through this filter: https://github.com/polylang/polylang/blob/3.1/include/model.php#L587-L595. A links model is a child class of PLL_Links_Model.

    I am not sure that using PLL_Links_Default (the model used for plain permalinks) directly with pretty permalinks would work (I never tested it). But maybe you can create a child class from PLL_Links_Directory (the default model used with pretty permalinks fro one domain) and override the method add_language_to_link() to add your query string. That way you let Polylang work as usual and you just add your query string to be interpreted by your other site.

    Thread Starter Daniel Letschka

    (@dinonid)

    Thank you!

    We solved it with javascript now. We check if the url contains “/en/” and depending on the result write a value to local storage.

    The non-wordpress-pages we link to are on a subdomain, so that works.

    Best,
    Daniel

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Append query string’ is closed to new replies.