Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a sitemaps plugin which in very complex ways sets the timezone of <lastmod> (i.e. last modified time) for posts to GMT.

Temporarily, until the plugin developer fixes it, I need to enforce a custom timezone on the plugin. The simple and straightforward way that I've found is to add something like date_default_timezone_set( 'America/New_York'); right after the first <?php in the file responsible for outputting the sitemaps.

It works, and it doesn't seem to affect timestamps displayed on the rest of the site. So, can I go with this? or is there a better solution?

share|improve this question

1 Answer 1

up vote 1 down vote accepted
+50

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.

share|improve this answer
    
Thanks for the suggestion, but the plugin's code is more complex than that. Please take a look: gist.github.com/201ec6b0c50317040837 — for instance, $date = date( 'c', strtotime( $date ) ); is later used like this: $this->sitemap .= '<lastmod>' . htmlspecialchars( $date ) . '</lastmod>' . "\n"; — And that's not all. Down the code, there's more. –  its_me Jul 6 '12 at 16:03
    
Ah, in that case: you don't need to do anything: gist.github.com/201ec6b0c50317040837#L321 Yoast uses the GMT date. –  chrisguitarguy Jul 6 '12 at 16:53
    
I don't want GMT. That's the problem. I need to set it to a different time zone (e.g. America/New_York). –  its_me Jul 6 '12 at 17:06
1  
Actually, I can't use the function. Reason: WP's date-time function is broken (by design, they say), and I had to fix that manually, as you can see here. Sorry about the growing complexity. Any changes I can make directly in the file would be fine. Thanks for your time. :) –  its_me Jul 7 '12 at 1:43
1  
Why do you want to change the lastmod time to not be GMT? Everything expects that value to be GMT, if you change it to something else, then your sitemap will be incorrect. These things are standards for a reason. –  Otto Jul 7 '12 at 22:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.