Skip Navigation

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

Problem:

The user says that wpml_get_translated_slug hook always returns slut in default language.

Here's the code that the user uses:

echo apply_filters( 'wpml_get_translated_slug', get_post_field( 'post_name' ), 'page', 'en'); exit();

Solution:

In this case there was a misuse use of this hook.

The hook you are using (wpml_get_translated_slug) is intended to get the post-type slug translation in a specific language. But you are misusing it. You are trying to get the slug of a particular page of WordPress. A regular WordPress page doesn't have this "slug prefix" type. Its permalink consists only of the page slug itself.

Let's, for example, take a custom post type with the name of 'book'. In this case, the following will consist of the permalink.

post type slug = book

post slug = my-book

permalink = /book/my-book/

The wpml_get_translated_slug hook filters the /book/ part. WordPress's pages do not have this part.
Relevant Documentation:

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

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 topic contains 2 replies, has 2 voices.

Last updated by davidC-175 2 years, 9 months ago.

Assisted by: Itamar.

Author Posts
March 17, 2022 at 2:48 pm #10813581

davidC-175

I have struggled with getting translated URL slug in a different language. I tried wpml_get_translated_slug but it returns to me only the same slug as is given in the method argument ...

I just need to get the URL slug of the default (English) of the current page/post...

March 20, 2022 at 7:49 pm #10832169

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

I'll continue helping you with this issue.

I've read the chat you've had with Max, my colleague, and looked into this matter further.

The hook you are using (wpml_get_translated_slug) is intended to get the post-type slug translation in a specific language. But you are misusing it. You are trying to get the slug of a particular page of WordPress. A regular WordPress page doesn't have this "slug prefix" type. Its permalink consists only of the page slug itself.

Let's, for example, take a custom post type with the name of 'book'. In this case, the following will consist of the permalink.

post type slug = book
post slug = my-book
permalink = /book/my-book/

The wpml_get_translated_slug hook filters the /book/ part. WordPress's pages do not have this part.

Please let me know if you have further questions about my answer.

Regards,
Itamar.