Chuyển đến nội dung Chuyển đến thanh bên

Open

Reported for: WPML SEO 2.1.0

Topic Tags: Compatibility

Overview of the issue

If you are using the Rank Math SEO plugin, specifically the Pro version with the News Sitemap feature enabled, you may encounter an issue where <news:language> tags within the news-sitemap.xml file incorrectly display the language code of the site’s default language for posts in secondary languages..

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Open …/wp-content/plugins/seo-by-rank-math-pro/includes/modules/news-sitemap/class-news-sitemap.php file.
  • Replace:
    		$output .= $this->get_news_publication( $renderer );
    
  • With:
    		//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
    
  • In addition, you may also need to disable sitemap caching. To do this, you can add the following line to the functions.php file of your theme:
    add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
    

Để lại trả lời

Vui lòng giữ đúng chủ đề và tôn trọng người khác. Nếu bạn cần trợ giúp với các vấn đề không liên quan đến bài đăng này, hãy sử dụng Diễn đàn Hỗ trợ của chúng tôi để bắt đầu trò chuyện hoặc gửi vé hỗ trợ.

Bạn có thể sử dụng các thẻ này:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>