Multilanguage website get the title, on different languages

I am working on a website, and I am using Polylang to translate it to a different language.
In my code I want to get a page title, and display it. My issue is I cannot get it by ID or page_by_path because its going to display the English version of the page on every language.

For example: I want to display the Contact page title on english Contact and on another language its equivalent translated contact page title.

Is there a way to do that?

The code that I’m using so far:

<?php $page = get_page_by_path( 'contact' ); ?>
<span><?php echo get_the_title( $page ); ?></span>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In polylang you can use the function pll_get_post($postID) to get the id of the translated page like this:

<?php echo get_the_title(pll_get_post(52)); ?>

I’d be glad if you rate my answer if it was useful.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x