Home / Admin / Change Time zone Offset in the Publish Date of the Sitemap Entries
Duplicate Snippet

Embed Snippet on Your Site

Change Time zone Offset in the Publish Date of the Sitemap Entries

The code snippet below can be used to change the time zone offset in the publish date of the sitemap entries. This can be useful for when a platform requires the date to be formatted to a specific timezone (e.g. Yandex News/Zen/Дзéн).

<10
Code Preview
php
<?php
add_filter( 'aioseo_sitemap_rss', 'aioseo_filter_rss_sitemap_entries' );
function aioseo_filter_rss_sitemap_entries( $entries ) {
	$entries = array_map( function ( $entry ) {
		if ( empty( $entry['pubDate'] ) ) {
			return $entry;
		}
		$dateTime = new DateTime();
		$dateTime->setTimestamp( strtotime( $entry['pubDate'] ) );
		$dateTime->setTimezone( new DateTimeZone( 'Europe/Moscow' ) );
		$entry['pubDate'] = date_format( $dateTime, 'D, d M Y H:i:s O' );
		return $entry;
	}, $entries );
	return $entries;
}

Comments

Add a Comment