- ステータス
- 未解決
- 報告対象
- WPML SEO 2.1.0
- 関連するプラグイン/テーマ
- Rank Math SEO
- トピックタグ
- Compatibility
問題の概要
Rank Math SEOプラグイン(特にNews Sitemap機能を有効にしているPro版)を使用している場合、セカンダリ言語の投稿において、news-sitemap.xmlファイル内の<news:language>タグがサイトのデフォルト言語の言語コードを誤って表示する問題が発生する可能性があります。
回避策
続行する前に、必ずサイトの完全なバックアップを取得してください。
- …/wp-content/plugins/seo-by-rank-math-pro/includes/modules/news-sitemap/class-news-sitemap.phpファイルを開きます。
- 次のコードを:
$output .= $this->get_news_publication( $renderer );
- 次のコードに置き換えます:
//start WPML workaround global $sitepress; remove_filter( 'get_pages', [ $sitepress, 'get_pages_adjust_ids' ], 1 ); $my_post_language_details = apply_filters( 'wpml_post_language_details', NULL, url_to_postid($url["loc"]) ); $xmlString = $this->get_news_publication( $renderer ); $pattern = '/(<news:language>)[^<>]*(</news:language>)/i'; $replacement = '${1}'. $my_post_language_details["language_code"] .'$2'; $modifiedXmlString = preg_replace($pattern, $replacement, $xmlString); $output .= $modifiedXmlString; //end WPML workaround - さらに、サイトマップのキャッシュを無効にする必要がある場合もあります。これを行うには、お使いのテーマのfunctions.phpファイルに次の行を追加します:
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');