3

I have a third party tool which extracts feed content from our WordPress site, via our RSS feed: http://ontariotravelblog.com/feed

The feed provides me with everything I need, except for the last updated date of the blog post; it does include the published date, however this is simply the date the blog was first published; edits / changes made to the blog after publication does not affect this date.

Now what's interesting is that the ATOM version of the feed (http://ontariotravelblog.com/feed/atom) does include both the published date and the updated date, for example:

 <entry>
  ...
    <title type="html">
        <![CDATA[8 Songs for Your Ontario Summer Road Trip Playlist]]>
    </title>
    <id>http://ontariotravelblog.com/?p=5621</id>
    <updated>2016-06-09T16:40:46Z</updated>
    <published>2016-05-10T16:25:35Z</published>
 ...
 </entry>

Which is great, except that the ATOM feed is missing some critical content (in particular, its missing a number of "media:" elements, such as media:thumbnail, etc.)

So after all this, my question: Is there a way to get the updated field which is included within the ATOM feed entry to appear on the main RSS feed? (perhaps via some config option?)

1 Answer 1

6

Atom vs RSS2

Let's look at the wp-includes/feed-atom.php and wp-includes/feed-rss2.php files.

The updated element of the Atom feed entry is:

<updated><?php 
    echo mysql2date(
        'Y-m-d\TH:i:s\Z', 
        get_lastpostmodified('GMT'), 
        false 
    ); 
?></updated>

The pubDate element of the RSS2 feed item is:

<pubDate><?php 
    echo mysql2date(
        'D, d M Y H:i:s +0000', 
        get_post_time('Y-m-d H:i:s', true), 
        false
    ); 
?></pubDate>

The lastBuildDate element of the RSS2 channel is:

<lastBuildDate><?php 
    echo mysql2date(
        'D, d M Y H:i:s +0000', 
        get_lastpostmodified('GMT'), 
        false
    ); 
?></lastBuildDate>

Namespace

The RSS2 feed already contains the Atom namespace:

xmlns:atom="http://www.w3.org/2005/Atom"

so I think we can use the <atom:updated> element for our custom updated element. You might want to check it out further, if that fulfills the standard or if there are other possible namespaces suitable for this.

For the latter case we can use the rss2_ns action to add the relevant namespace.

Inject a custom element

We can use the rss2_item action to inject custom item elements, like:

add_action( 'rss2_item', function()
{   
    printf( 
        '<atom:updated>%s</atom:updated>',
         get_post_modified_time( 'D, d M Y H:i:s +0000', true )
    );

} );

Hopefully you can adjust it to your needs.

2
  • Absolutely wonderful answer - with great detail. Unfortunately I just found out that you can't actually modify these files on sites hosted on WordPress.com - only on self hosted sites. I had hoped there would be a config setting somewhere which would allow this, but after chatting with WP.COM support staff, apparently not. In any case, I'm going to mark this as the correct answer as it sure sounds like it would work great, I just can't verify it myself since this is not a self hosted site.
    – RMD
    Jun 15, 2016 at 14:38
  • Maybe you could join the atom+rss2 feeds with some external service or application (custom) or setup your own WordPress install ;-) @RMD
    – birgire
    Jun 15, 2016 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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