0
votes

I have a question about linking the right page with Polylang.
I have a hard-coded anchor, which is basically a “back home” link. It looks like this:

<a href=“magazin” class=“article-type-inner”><?php pll_e(‘Close’); ?></a>

I have already implemented a string and it works fine in the posts in both languages, but how can I change the “Href” to the right language?

For example my default language is English and the other language is French. If I am on a french post I will return to the English page… Is there any solution?
Thank you.

1

1 Answers

0
votes

Ideally you should not hardcode any strings or URL's, here is some options for you:

  • Use pll_home_url() if your intention is to redirect to the home page. pll_home_url() accepts optional parameter $slug (2-letters code of the language) to switch between languages if needed.
  • Use get_permalink(), the_permalink() or get_the_permalink(). You can pass page_id as first argument. Make sure post/pages/cpt's are linked properly. E.g. the_permalink(100).
  • Worst case scenario - use if/else in combination with pll_current_language(). Not recommended.