Is it safe to use ‘date_default_timezone_set’ in plugin file?

http://codex.wordpress.org/Function_Reference/get_gmt_from_date

Replace all instances of get_the_date or the_date with echo get_gmt_from_date(get_the_date('Y-m-d H:i:s')). That’s not a quick fix, it’s a way to fix your sitemaps.

EDIT:

WordPress SEO runs it’s raw dates from MySQL through a WP function called mysql2date, which in turn calls date_i18n. date_i18n happens to have a handy filter which you can tie into to change the date:

<?php
add_filter('date_i18n', 'wpse57195_filter_date', 10, 4);
/**
 * Changes the date on WordPress SEO's sitemaps
 *
 * @return string The Date
 */
function wpse57195_filter_date($date, $format, $timestamp, $gmt)
{
    // if this isn't a sitemap page, bail
    if(!get_query_var('sitemap'))
        return $date;

    // W3C Time format with -05:00 for central time
    // NOTE: this doesn't account for daylight saving time
    $f="Y-m-d\TH:i:s-05:00";
    return $gmt ? gmdate($f, $timestamp) : date($f, $timestamp);
}

In the hooked function, you can check for the sitemap query variable and change the time as you need. To keep with the sitemap spec, you have to use the W3C date format which includes a +/- field for timezone. -05:00 is the number for central, daylight savings time. You can wrap the above up in a plugin and activate it until the sitemap can be fixed.

Leave a Comment