Search code examples
phpwordpresspolylang

Get homepage of a website of selected languge in Wordpress + Polylang


In my Wordpress + Polylang website, accueil is the page name of homepage in French and inicio is the page name of homepage in Spanish.

So the homepages are:

English : https://www.example.com
French  : https://www.example.com/fr/accueil/
Spanish : https://www.example.com/es/inicio/

Is it possible to get the homepage url of a selected language?

I use home_url() to get the homepage.

And I use pll_current_language() polylang function to get the selected polylang language code of the website.

But home_url() returns same English homepage url even if I select any other language.


Solution

  • You can use pll_home_url() as for docs. It accepts an argument (the language for the desired homepage).

    (string) pll_home_url(  $lang = '' );