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.

16 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
  3. Nice post........Thank you for sharing such a useful information about SEO with us......It really helped a lot Fake Comment Creator word press plugin

    ReplyDelete
  4. Keep up the great work, its hard to find good ones.
    seo backlinks service

    ReplyDelete
  5. We are really grateful for your blog post. You have done a great job. I will definitely dig it and personally recommend to my friends
    High Trus Flow and Citation Flow backlinks

    ReplyDelete
  6. please tell me my problem is still

    ReplyDelete
  7. please tell me my problem is still

    ReplyDelete
  8. Looking at ranking 1st in Google? Looking to grow your business? Look no further, we are Engage Online, an SEO Agency from Australia. Our SEO services maximise business marketing, boost traffic to websites, and raise Google Ranking
    SEO Australia

    ReplyDelete
  9. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject.
    Niche comment

    ReplyDelete
  10. I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
    website traffic

    ReplyDelete
  11. This blog helped me to understand the fact that even a simply written article can be best over thousands of other highly qualified no-meaning articles. So always keep in mind that use simple but accurate parameters for your blog.
    fiscalist amsterdam

    ReplyDelete
  12. I should say only that its awesome! The blog is informational and always produce amazing things. WordPress Hosting

    ReplyDelete