Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting page language and redirecting to same language page via polylang

I'm using polylang to translate my wordpress website and it's working fine until now...

The default language is english. Let's say I'm in a page in french, with a link to another page. I'd like it to be linked to that other page in french.

<a href="http://localhost:8888/lacolmena/a-propos/" class="apropos">

You'd say just add /fr at the end of the link. The thing is, I want it to detect which language is currently on and redirect the link to the equivalent language for the page I'm looking to get to.

Using Polylang, I managed to get all of my pages translated and working smoothly. I have a functional menu that allows me go to anywhere I want to go in any language. Only one link, in one page is causing me problems because it doesn't know if it could go the /fr or /en.

So I need to find a way to get if the current link if /fr or /en and redirect to the page in the equivalent language.

Basically :

my page is in french
go to the french contact page

or

my page is in english
go to the english contact page

I have no idea how to get to that. Should I be using PHP ? I've never used PHP before, so that's kind of creeping me out, even though I'm willing to make an effort to learn it.

I've seen this Polylang function while researching, perhaps it could be a beginning for my algorithm ?

pll_current_language($value);

I'm not sure my description is clear.. I'm really lost here :/

like image 400
Thaddé Méneur Avatar asked Oct 19 '22 21:10

Thaddé Méneur


2 Answers

setup <?php get_the_permalink(pll_get_post(get_page_by_path( 'page-slug' )->ID));?>

url path <a href="<?php echo get_the_permalink(pll_get_post(get_page_by_path( '**YOUR PAGE SLUG HERE**' )->ID));?>">URL TEXT</a>

like image 52
kengi Avatar answered Oct 27 '22 10:10

kengi


Try

get_the_permalink(pll_get_post(get_page_by_path( 'page-slug' )->ID));

It could look something like this

<a href="<?php echo get_the_permalink(pll_get_post(get_page_by_path( 'contact' )->ID));?>">Contact</a>
like image 26
mauricioabisay Avatar answered Oct 27 '22 10:10

mauricioabisay