Title: add_filter
Last modified: May 29, 2022

---

# add_filter

 *  Resolved [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/)
 * Hello,
    I need to make a filter. Can you please tell me which add_filter parameter
   to specify for sitemap-news.xml?
 * > add_filter( ‘**???**‘, ‘function_name’ );

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/add_filter-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/add_filter-2/page/2/?output_format=md)

 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15692032)
 * Hi, there are several filters available so it depends on what you want to do.
   You can see a quick overview on [https://premium.status301.com/knowledge-base/xml-sitemap-google-news/all-available-action-and-filter-hook/](https://premium.status301.com/knowledge-base/xml-sitemap-google-news/all-available-action-and-filter-hook/)(
   look for Context: Google News)
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15693914)
 * [@ravanh](https://wordpress.org/support/users/ravanh/) I need to replace the 
   values of several locales, because of incorrect slugs/locales in some languages.
   The replacement needs to be done line by line because some slugs are not in ISO
   639.
    I need an attribute to call the Google News site map generation, like ‘
   the_excerpt’, ‘the_content’, ‘wp_head’…
 * functions.php:
 * >  function replace_langgn($text){
   >  $replace = array( ‘<news:language>br</news:
   > language>’ => ‘<news:language>pt-BR</news:language>’, ‘<news:language>en_US
   > </news:language>’ => ‘<news:language>en-US</news:language>’, ‘<news:language
   > >pt_PT</news:language>’ => ‘<news:language>pt-PT</news:language>’ ); $text 
   > = str_replace(array_keys($replace), $replace, $text); return $text; } add_filter(‘**?????**‘,‘
   > replace_langgn’);
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15693915)
 * As far as I understand xmlsf_post_language is not suitable for me. It only takes
   values. And I can’t for example change the wrong slug ‘br’ (Brazil), to locale
   language-country ‘pt-BR’, so as not to break the layout of the xml.
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15693920)
 * Yes, I have a strange way to set some slugs) But it was necessary to set subdomain
   urls via polylang.
 * **What else I wanted to ask. Is it possible in the future to do site map filtering
   by language for multilingual sites using WPML, Polylang and other plugins?**
 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15695274)
 * Hi, the plugin should be compatible with Polylang so I’m surprised that you are
   encountering invalid language tag. Have you changed the language Locale `pt_BR`
   to `br` in Polylang? It’s better to leave the **Locale** as it is and only change
   the **Language code** field…
 * Anyway, the filter `xmlsf_post_language` should be `xmlsf_news_language` (sorry
   for the mistake in the documentation) and could work like this:
 *     ```
       function replace_langgn( $lang ) {
       	if ( $lang === 'br' ) {
       		return 'pt-BR';
       	}
       	return $lang;
       }
       add_filter( 'xmlsf_news_language', 'replace_langgn', 100 );
       ```
   
    -  This reply was modified 4 years ago by [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/).
    -  This reply was modified 4 years ago by [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/).
      Reason: fix priority
 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15695508)
 * Please note that the language code inside a GN sitemap should be in ISO 639 format.
   The code `pt-BR` is not ISO 639-1 or -2. You might want to change it to `pt` 
   or `por`. See more on [https://developers.google.com/search/docs/advanced/sitemaps/news-sitemap](https://developers.google.com/search/docs/advanced/sitemaps/news-sitemap)
   and the table on [http://www.loc.gov/standards/iso639-2/php/code_list.php](http://www.loc.gov/standards/iso639-2/php/code_list.php)
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15696213)
 * > Hi, the plugin should be compatible with Polylang so I’m surprised that you
   > are encountering invalid language tag.
 * It is compatible. Slug and Locale from Polylang outputs correctly (as configured).
   
   It’s just that I have languages implemented on subdomains en.site.com, pt.site.
   com… And the sitemap on all subdomains is the same (common to all). It would 
   be great if the site.com would be common (and more correct, if the default language),
   and the en.site.com posts in English, pt.site.com posts in Portuguese…
 * > Have you changed the language Locale pt_BR to br in Polylang? It’s better to
   > leave the Locale as it is and only change the Language code field…
 * I didn’t change the locales. I had to change the slugs. Because Polylang sets
   subdomain names depending on the language (slugs).
    And I have 2 English, 2 Portuguese(
   pt_PT for Portugal and pt_BR for Brazil). That’s why it’s mixed up.
    -  This reply was modified 4 years ago by [eddie](https://wordpress.org/support/users/ediet/).
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15696233)
 * > Please note that the language code inside a GN sitemap should be in ISO 639
   > format.
 * Only ISO 639?
 * > The code pt-BR is not ISO 639-1 or -2.
 * pt-BR (Portuguese for Brazil) – ISO 3166-1 Alpha 2
 * > pt_PT, pt_BR, en_US
 * Not standard at all. It is unclear why this is on so many sites and in WordPress
   by default. Must be pt-PT, pt-BR, en-US…
 * And Serch Console Google gives an error on it (en_US…).
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15696237)
 * Thanks for the replies! 🙂
 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15696873)
 * The plugin takes the first two letters from the Locale that is set for the language
   of each post. So a post in Brazilian Portuguese or European Portuguese will have`
   pt` as its language code in the Google News sitemap. This is different from the
   language code used in the HTML header.
 * Are you seeing tags like `<news:language>br</news:language>` or `<news:language
   >en_US</news:language>` in your Google News sitemap source code? This should 
   not be happening…
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15697919)
 * > The plugin takes the first two letters from the Locale that is set for the 
   > language of each post
 * That’s not exactly true. The plugin takes ‘slug’ from Polylang, not the first
   2 characters of ‘locale’.
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15697978)
 * The ‘slug’ and ‘locale’ may be different. Forced.
    If you have several identical
   languages but for different countries, you are forced to change the ‘slug’. Because
   the ‘slug’ has to be unique. Polylang just doesn’t allow you to do otherwise –
   that’s what urls are formed from, whether they are folders or sub-domains.
 * So here are some examples.
    1. I have two English ones. en_US and en_UK (this
   is how it’s implemented in WordPress, and later Polylang rewrites <html lang=”
   en-US”> and <html lang=”en-UK”> accordingly; if the same article is translated
   into both languages, then in hreflang=”en-US” and hreflang=”en-UK” according 
   to ISO 3166-1 Alpha 2). But I can’t set both of them to ‘slug’ – en. It gives
   me an error. So for one of the languages I have to manually prescribe a non-existent
   in 2 characters ISO 639-1 (e.g. uk for UK – although this is an error). 2. Same
   with pt_PT (Portuguese for Portugal) and pt_BR (Portuguese for Brazil). I cannot
   set for both pt.
 * Your code takes the ‘slug’ from Polylang:
 * > <?php echo apply_filters( ‘xmlsf_news_language’, xmlsf()->blog_language(), 
   > $post->ID, $post->post_type ); ?>
 * blog_language =’slug’
    blog_language != first 2 characters of ‘locale’
 *  Thread Starter [eddie](https://wordpress.org/support/users/ediet/)
 * (@ediet)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15698019)
 * > Are you seeing tags like <news:language>br</news:language> or <news:language
   > >en_US</news:language> in your Google News sitemap source code? This should
   > not be happening…
 * I was just experimenting with different options. And output instead of your line:
   `
   <news:language><?php echo apply_filters( 'xmlsf_news_language', xmlsf()->blog_language(),
   $post->ID, $post->post_type ); ?></news:language>`
 * Other strings using Polylang functions:
    `<news:language><?php echo pll_get_post_language(
   $post->ID, 'locale'); ?></news:language>` `<news:language><?php echo pll_get_post_language(
   $post->ID, 'slug'); ?></news:language>`
    -  This reply was modified 4 years ago by [eddie](https://wordpress.org/support/users/ediet/).
 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15700007)
 * > That’s not exactly true. The plugin takes ‘slug’ from Polylang, not the first
   > 2 characters of ‘locale’.
 * You may have caught a bug… I’ll verify this.
 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [4 years ago](https://wordpress.org/support/topic/add_filter-2/#post-15700829)
 * If you could, please go to Plugins > Plugin File Editor and select XML Sitemap&
   Google News. Then browse to the file xml-sitemap-feed/models/functions.public-
   sitemap-news.php and edit line 150 from:
 *     ```
       $language = pll_get_post_language( $post_id, 'slug' );
       ```
   
 * to
 *     ```
       $language = pll_get_post_language( $post_id, 'locale' );
       ```
   
 * (basically only changing “slug” to “locale”) and hit Update File.
 * Please let me know how that works out 🙂

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/add_filter-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/add_filter-2/page/2/?output_format=md)

The topic ‘add_filter’ is closed to new replies.

 * ![](https://ps.w.org/xml-sitemap-feed/assets/icon-128x128.png?rev=1112143)
 * [XML Sitemap & Google News](https://wordpress.org/plugins/xml-sitemap-feed/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/xml-sitemap-feed/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/xml-sitemap-feed/)
 * [Active Topics](https://wordpress.org/support/plugin/xml-sitemap-feed/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/xml-sitemap-feed/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/xml-sitemap-feed/reviews/)

 * 17 replies
 * 2 participants
 * Last reply from: [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * Last activity: [4 years ago](https://wordpress.org/support/topic/add_filter-2/page/2/#post-15707346)
 * Status: resolved