A GitHub Issue Journey: The Case of the Missing Dates (XML Sitemap & Google News feeds)

Solving GitHub Issue #54: The Case of the Missing Dates

In GitHub issue #54, users encountered a puzzling error: ‘An invalid date was found.’ The culprit? An empty ‘lastmod’ attribute on designated homepage and blog pages. The investigation led to a discovery: the plugin was retrieving dates from non-existent blog posts. Collaboratively, the community proposed solutions, ensuring accurate date retrieval for pages. Ultimately, GitHub issue #54 exemplified the power of community collaboration in resolving software mysteries.

I utilized the “XML Sitemap & Google News Feeds” plugin to generate a sitemap for my e-commerce shop, which is powered by @RavanH. Despite not having any blog posts on our website, we designated specific pages for the homepage and blog page. However, the modified dates of these two pages in the sitemap file do not reflect the actual dates.

In the file functions-public-sitemap.php, there’s a condition that deals with front pages. Essentially, if a page is set as a front page and it’s of type ‘page’, the code retrieves its last modification date using get_lastpostdate(). However, here’s the catch: if your website doesn’t have any blog posts, the return value of get_lastpostdate() will be empty, causing the bug to rear its head.

The solution? It’s a simple tweak in the code:

Solution 1:

Instead of:

$lastmod = get_lastpostdate( 'GMT', 'post' );


$lastmod = get_lastpostdate( 'GMT', 'page' );

Why? Because you want to fetch the last modified date of your front pages specifically, and thus you should use the related post type (‘page’).


Solution 2:

Another option is to set the $lastmod variable to the current date:

$lastmod = date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) );

This ensures that search engine bots recognize the page as recently updated, even if it doesn’t have any blog posts.


Solution 3: (Not-recommended)

But what about creating an empty blog post to fix the issue temporarily? It might seem like a quick fix, but it’s flawed. By creating an empty post, the modified date of your front pages remains static, failing to reflect their actual modification status.


In conclusion, when dealing with front page dates in WordPress, a small adjustment in the code can go a long way in ensuring smooth functionality without resorting to makeshift solutions.