xmlsf_news_language

Filters the post language code used in the news sitemap. Passes additional variables $post_id and $post_type;

apply_filters( 'xmlsf_news_language', string[] $locale, int[] $post_id, string[] $post_type )

Used in xml-sitemap-feed/views/feed-sitemap-news.php

Parameters (3)

  • $locale
    (string) Site language taken from get_bloginfo('language') or from Polylang or WPML post data. Usually a ICU locale string that will get converted into ISO 639 language code at priority 99.
  • $post_id
    (int) The current post ID.
  • $post_type
    (string) The current post type.

Return

  • (string) ISO 639 language code

The filter should return a 2 or 3 letter ISO 639 language code with the exception of zh-cn and zh-tw. If your filter returns a more commonly used ICU locale code (usually made up out of a ISO 639 language code and a ISO 3166 code, separated by a hyphen or underscore) then make sure to keep the filter priority below 99. At priority 99 the code will get stripped down by the filter xmlsf_parse_language_string() into its ISO 639 only part.

Usage example

function my_custom_lang( $lang, $post_id ) {
	// Get my custom post language meta data.
	$post_language = get_post_meta( $post_id, 'language', true );
	if ( ! empty( $post_language ) ) {
		$lang = $post_language;
	}

	// Return language code.
	return $lang;
}
add_filter( 'xmlsf_news_language', 'my_custom_lang', 10, 2 );

Related

Used byDescription
xml-sitemap-feed/inc/functions.public-sitemap-news.php: xmlsf_polylang_post_language_filter()Post language filter for Polylang.
xml-sitemap-feed/inc/functions.public-sitemap-news.php: xmlsf_wpml_post_language_filter()Post language filter for WPML.
xml-sitemap-feed/inc/functions.public-sitemap-news.php: xmlsf_parse_language_string()Parses language string into two or three letter ISO 639 code. This filter passes at priority position 99.