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.

This thread is resolved. Here is a description of the problem and solution.

Problem: Get URL of post in different language

Solution: Recommended *wpml_permalink* hook for this purpose, like the following example. It will return French URL of the post.

$url = get_the_permalink();

$wpml_permalink = apply_filters( 'wpml_permalink', $url , 'fr' );

Relevant Documentation: https://wpml.org/wpml-hook/wpml_permalink/

100% of people find this useful.

Tagged: 

This topic contains 3 replies, has 3 voices.

Last updated by Makarand Mane 2 years, 12 months ago.

Assigned support staff: Bigul.

Author Posts
October 19, 2016 at 5:29 pm #1118915

evaB-5

Hi,

I'm trying to add an automatic link to the translation of a post in a custom post type single.php template.

Basically what I want is:

Language 1: Click here to see the post in language 2.
Language 2: Click here to see the post in language 1.

I have no issues getting the right ID for the translated post, as follows:

$lang_post_id = icl_object_id( $post->ID , 'newsletter', true, $language );

But whenever I want to get the permalink based on this ID I still get the permalink of the post in the current language.

$url = get_permalink($lang_post_id);

I'm thinking I have to add something before outputting the get_permalink function so it won't revert back to the current language. Any idea how to do this?

Thanks!

October 20, 2016 at 6:21 am #1119150

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi ,

Thank you for contacting the WPML support. We are happy to help you.

You can use *wpml_permalink* hook for this purpose, like the following example. It will return French URL of the post.

$url = get_the_permalink();

$wpml_permalink = apply_filters( 'wpml_permalink', $url , 'fr' );

Please check following tutorial for more details.

https://wpml.org/wpml-hook/wpml_permalink/

--
With Regards

Bigul

October 20, 2016 at 7:41 am #1119209

evaB-5

Thank you! That works like a charm.

Eva

October 2, 2019 at 1:52 pm #4681045

Makarand Mane

Hi Bigul

I need links in original language. I tried to remove all filters on wpml_permalink & post_link but nothing works..

	remove_all_filters( 'wpml_permalink' );
	remove_all_filters( 'post_link'  );

$url = get_permalink( $id );

It still gives me converted url in another language