Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 7 replies, has 3 voices.

Last updated by Wes Couch 1 year, 9 months ago.

Assisted by: Long Nguyen.

Author Posts
August 10, 2023 at 9:36 pm #14185143

Wes Couch

Tell us what you are trying to do?
I'm trying to use get_permalink() WP core function to get the page URL depending on the passed post ID parameter. This is returning the translated page URL in the current language, whether I'm passing in a current language post ID or another language post ID. I have read several help articles and my understanding is get_permalink() will get the page URL, regardless of language. We want to be able to link to either English or Dutch (NL) pages, and not necessarily the page's language translation.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link
hidden link

In the top of the header area I am passing an array of page IDs ['10', '18', '7994'] to do a get_permalink() test. The absolute URLs are translated depending on whether you're on English or Dutch home page.
8 => Home (EN)
18 => Home (NL)
7994 => Data Breaches (EN)

get_permalink_always_translated.PNG
August 11, 2023 at 11:21 am #14188083

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

while you wait for one of my colleague to take over the case, to speed things up, please follow next steps:

I created a minimal installation of WordPress, WPML, and all necessary WPML add-ons.

You can access the WordPress dashboard using the link below:
- hidden link

Kindly follow the steps below:
- Set up WPML
- Try to replicate the issue with WP default theme and dummy simple example
- Share with me step by step guide on how can I check the issue and steps you did

This will help us to report the possible problem faster.

Regards,
Drazen

August 14, 2023 at 11:45 pm #14200409

Wes Couch

Hello Drazen,
Appreciate the quick reply. I have done the steps you listed and the result is the same on the provided WordPress environment. If you go to the home page, you will see in the top of the screen I am echoing various pages with get_permalink() to get the page URL, regardless of language. But, the links are displaying the page URL only in current language, instead of absolute. If I want to get a Dutch URL, get_permalink() does not do so.

Let me know if you need more information at this time. Thank you!

Edit: Sorry, forgot to mention that I added those get_permalink() echo in the header.php of the active Twenty Twenty-One theme.

August 15, 2023 at 7:00 am #14201373

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi Wes,

Thank you for contacting WPML support, I'd be happy to help you with this issue.

It happens when the option "Adjust IDs for multilingual functionality" is enabled. You can go to WPML > Languages > Make themes work multilingual section > Disable this option and check the permalink again.

Look forward to your reply.
Thanks

August 15, 2023 at 4:37 pm #14204395

Wes Couch

Hello,

I followed your instructions, and do see that works when disabling the "Make themes work multilingual section" option. However, disabling this option seems to remove all multilingual functionality from the site. Is this intended? Is there a way to have multilingual functionality and the ability to get URLs using absolute ID?

Thanks in advance

August 16, 2023 at 3:32 am #14205847

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Yes, it is expected. If you enable that option, WPML attempts to adjust the content/ID and display the content of the current language.
You can also use the filter hook "wpml_permalink" to get the permalink of the translation page. For example:

echo 'About Us(nl): ' . apply_filters( 'wpml_permalink', get_the_permalink( 56 ), 'nl' );

Refer to the documentation https://wpml.org/wpml-hook/wpml_permalink/

Look forward to your reply.
Thanks

August 16, 2023 at 10:16 pm #14241463

Wes Couch

Thanks, I was able to get it working with the filter hook! For anyone coming here in the future, here's how I was able to create that:

August 16, 2023 at 10:20 pm #14241469

Wes Couch

Thanks, I was able to get it working with the filter hook! For anyone coming here in the future, here's how I was able to create that:

$wpml_post_lang = apply_filters( 'wpml_post_language_details', NULL, $post_id );
$post_lang_code = $wpml_post_lang['language_code'];
$post_link = apply_filters( 'wpml_permalink', get_the_permalink( $post_id ), $post_lang_code );

wpml_get_permalink.PNG