You appear to be a bot. Output may be restricted
Description
Construct the news sitemap url entry for a WP_Post.
Usage
$string = Jetpack_Sitemap_Builder::post_to_news_sitemap_item( $post );
Parameters
- $post
- ( WP_Post ) required – The post to be processed.
Returns
string An XML fragment representing the post URL.
Source
File name: jetpack/modules/sitemaps/sitemap-builder.php
Lines:
1 to 79 of 79
private function post_to_news_sitemap_item( $post ) { /** * Filter condition to allow skipping specific posts in news sitemap. * * @module sitemaps * * @since 3.9.0 * * @param bool $skip Current boolean. False by default, so no post is skipped. * @param WP_POST $post Current post object. */ if ( apply_filters( 'jetpack_sitemap_news_skip_post', false, $post ) ) { return array( 'xml' => null, ); } $url = get_permalink( $post ); /* * Spec requires the URL to be <=2048 bytes. * In practice this constraint is unlikely to be violated. */ if ( 2048 < strlen( $url ) ) { $url = home_url() . '/?p=' . $post->ID; } /* * Trim the locale to an ISO 639 language code as required by Google. * Special cases are zh-cn (Simplified Chinese) and zh-tw (Traditional Chinese). * @link https://www.loc.gov/standards/iso639-2/php/code_list.php */ $language = strtolower( get_locale() ); if ( in_array( $language, array( 'zh_tw', 'zh_cn' ), true ) ) { $language = str_replace( '_', '-', $language ); } else { $language = preg_replace( '/(_.*)$/i', '', $language ); } $item_array = array( 'url' => array( 'loc' => $url, 'lastmod' => jp_sitemap_datetime( $post->post_modified_gmt ), 'news:news' => array( 'news:publication' => array( 'news:name' => html_entity_decode( get_bloginfo( 'name' ) ), 'news:language' => $language, ), /** This filter is already documented in core/wp-includes/feed.php */ 'news:title' => apply_filters( 'the_title_rss', $post->post_title ), 'news:publication_date' => jp_sitemap_datetime( $post->post_date_gmt ), 'news:genres' => 'Blog', ), ), ); /** * Filter associative array with data to build <url> node * and its descendants for current post in news sitemap. * * @module sitemaps * * @since 3.9.0 * * @param array $item_array Data to build parent and children nodes for current post. * @param int $post_id Current post ID. */ $item_array = apply_filters( 'jetpack_sitemap_news_sitemap_item', $item_array, $post->ID ); return array( 'xml' => $item_array, ); }