Yoast / wordpress-seo

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

Wrong news sitemap when using WPML translations #19726

Closed manuelaugustin closed 2 months ago

manuelaugustin commented 1 year ago

Moved from https://yoast.atlassian.net/browse/IM-39

When using WPML, News SEO generates a news sitemap for each language which is great, however, they are not totally correct

For example, for these two articles:\ /my-article (English version)\ /es/mi-articulo (Spanish version)

The news sitemap for the English language includes both articles and the news:language is set to English for both of them

bacc40ac-18ea-11e6-8956-7814d74b04ff

The news sitemap for the Spanish language includes both articles and the news:language is set to Spanish for both of them

039fb732-18eb-11e6-8a8c-01c702c8e6b4

WordPress 4.5.2\ Yoast SEO 3.2.5\ News SEO 3.2\ WPML Multilingual CMS 3.3.8

manuelaugustin commented 1 year ago

Please inform the customer of conversation # 826994 when this conversation has been closed.

manuelaugustin commented 1 year ago

Comments:

Tested this with latest WordPress 5.7.2, WPML SEO 2.0.0 and WPML 4.4.10 and the news-sitemap.xml still shows the same languages for all posts, whatever is configured in WPML as language.

b6089549-87a9-437b-9957-22fa0304aa99

dgwatkins commented 1 year ago

This is David from the WPML compatibility team.

Some time ago I requested a new filter to address this issue (for reference, it was in https://github.com/Yoast/bugreports/issues/278)

This was the suggestion I made:

diff --git a/classes/sitemap-item.php b/classes/sitemap-item.php
index 1f5e7b5..aea09b5 100644
--- a/classes/sitemap-item.php
+++ b/classes/sitemap-item.php
@@ -143,7 +143,7 @@ class WPSEO_News_Sitemap_Item {
         */
        private function build_publication_tag() {
                $publication_name = WPSEO_Options::get( 'news_sitemap_name', get_bloginfo( 'name' ) );
-               $publication_lang = $this->get_publication_lang();
+               $publication_lang = apply_filters( 'Yoast\WP\News\publication_language', $this->get_publication_lang(), $this->item );

                $this->output .= "\t\t<news:publication>\n";
                $this->output .= "\t\t\t<news:name>" . $publication_name . '</news:name>' . "\n";

I'm not sure if the code has changed, but we basically need a hook to adjust the language of a publication and we can take it from there.

laurasacco commented 3 months ago

Please inform the customer of conversation # 1147423 when this conversation has been closed.