Pages

Tuesday, June 25, 2013

Invalid Date Error in Google Webmaster for Sitemap generated by WordPress SEO by Yoast


If you have recently tested your sitemap that is generated by Yoast plugin for WordPress SEO, then you might have encountered an error in Google Webmaster tools while adding or testing the sitemap.

The error type would usually be mentioned as "invalid date". To fix this, one of the plugin file in Yoast SEO plugin need to be edited. Thanks to a contributor (roaming_elephant) in WordPress support forum, part of the code needs replacement. Here are the step-by-step procedures to fix this problem:

Step 1: open the plugin folder and open this php file: wordpress-seo/inc/class-sitemaps.php

Step 2: Go to line 249 and 250 where you will find the below code:
if ( $query->have_posts() )
 $date = $query->posts[0]->post_modified_gmt;
Replace the above code with the below given code:
if ( $query->have_posts() ) {
  $date = $query->posts[0]->post_modified_gmt;
  $date = date( 'c', strtotime( $date ));
}
That is all you need to do. You can now go to google webmaster tools and retest your sitemap that is generated by yoast. It should return no errors. If you have any questions, feel free to comment here.

2 comments:

  1. I have been looking for a solution in a while, and I am glad you posted this,however this did not solve the problem. The invalid dates I get are 1969-12-31 16:00 under the following:

    /category-sitemap.xml
    /post_tag-sitemap.xml

    All else is fine, and was already fine. If you know, please let us know. Thanks!

    ReplyDelete
  2. Thanks WP Kid and roaming-elepant,

    I had the same symptoms with Yoast's (ahem) five star SEO plugin. I then discovered this post as the #1 SER on the phrase, "yoast seo invalid date google webmaster." Then I realized...

    I hadn't updated the culprit-site's plugins in a month or so... and this post is dated June 25th. So... I updated the Yoast plugin and... voila, no more webmaster date error.

    Looks like Yoast and co. are listening. Maybe not a perfect five star, but he/they get it.

    ReplyDelete