Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.78k stars 895 forks source link

WMPL rest api returns wrong language #17847

Open mooksz opened 2 years ago

mooksz commented 2 years ago

Please give us a description of what happened.

I'm trying to retrieve seo meta data from the REST-Api for a multilangual headless WordPress & Next.js App project. The REST-api however returns the data based on a wpml variable, I expect after some inspecting the wp-wpml_current_admin_language_[some_id] or wp-wpml_current_language cookie.

E.g. i fetch https://mydomain.nl/wp-json/yoast/v1/get_head?url=https://mydomain.nl/en/contact/ with wp-wpml_current_admin_language_[some_id] set to en i get the correct data back. But if its set to nl I'm getting the dutch translated data back. My front-end app wont send this cookies nor knows the correct cookie id. I tried WPGraphql icm with WPGraphl SEO and WPGraphql WMPL but same issue.

Please describe what you expected to happen and why.

I expect to receive the correct data corresponding to the page id or url I'm trying to fetch instead of the language that the current logged in cms user has set as current language.

How can we reproduce this behavior?

  1. Install Yoast, WMPL and WPML SEO. Fetch api for a translated page, see results. Then switch the language in CMS or try to fetch again in an incognito tab and see different data.

Technical info

Used versions

Djennez commented 2 years ago

@mooksz I am not really sure what it is that you're experiencing as a bug.

On my local test installation (WPML set to use all languages in a subdirectory), I have 2 posts:

On both pages I have added a description in the language that is represented by the post.

Requesting http://basic.wordpress.test/wp-json/yoast/v1/get_head?url=http://basic.wordpress.test/en/language/ provides me with the English description metadata of the English post, as expected.

Requesting http://basic.wordpress.test/wp-json/yoast/v1/get_head?url=http://basic.wordpress.test/nl/taal/ provides me with the Dutch description metadata, also as expected.

mooksz commented 2 years ago

@Djennez thanks for the reply! Do you also receive the correct data in a private window? Or is this after changing the language in WordPress.

I do have a staging environment. Could share the credentials for you to take a look? Would appreciate it!

Djennez commented 2 years ago

All data is language specific, both with and without the session. I can run a curl request to both endpoints and still get the taal description from the Dutch post and the language description from the English post.

If you need support, I'd advise to visit the free forums or contact our premium support (in case of Yoast SEO Premium). But since your experience is with a third party, I am unsure how much our support will be able to go into detail.

mooksz commented 2 years ago

Oh my apologiez, I just noticed its only the og_locale that is incorrect. I am receiving the correct description and such but the OG:locale for example is based on the cookie. Cookie set to en I receive "og_locale": "en_US" with cookie set to nl I get "og_locale": "nl_NL". In a private window or via curl I think it does a fallback to the default language? Which is dutch in my case. So I always receive "og_locale": "nl_NL". Even with header accept-language: en-GB,en;q=0.9

I thought I read on the WMPL website you guys made the WMPL to Yoast plugin, is this incorrect?

mooksz commented 2 years ago

I've just tested it with all other data, but all is received correct. Only og_locale is returned incorrect.

Djennez commented 2 years ago

I thought I read on the WMPL website you guys made the WMPL to Yoast plugin, is this incorrect?

Nope, that's maintained by WPML.

I see that my locale is set to English regardless. I haven't checked if WPML is supposed to change that. I believe Yoast just uses a site setting and maybe that's overridden by WPML, in which case this would need to be fixed in that glue plugin.

I'll have a look where that is supposed to be set.