Saturday 14 Jun 2008

Switch from RSS to Atom feeds

atom-enabledWhat we generally call RSS feeds can be in fact feeds from different formats: RSS 1 (or 0.9), RSS 2 or Atom.

The last one has an advantage (very important for a real geek) on the RSS format: it's not proprietary and supported by the W3C. ;-) Moreover it brings additional elements for more content.

That's why I decide to put the link on the Atom feed on my blog. Here is how to do:

With WordPress the 3 versions are generated.

  1. gives RSS 2 feed,
  2. gives RSS 0.92 feed,
  3. gives Atom feed.

If there are links to the RSS 2 feed in your theme you can easily replace them by /feed/atom. And for the main feed in the browser address bar, it's in the header (generally the header.php file in the theme).

You must write in first, or suppress the 2 others, the link to Atom:
<link rel="alternate" type="application/atom+xml" title="Atom feed" href="" />


If you build yourself your own RSS feed from your site, the best is to manualy write the code. I tried a existing class to generate feeds, but it's more complicated than generate it myself! :-p


Atom feed example for you to create it with PHP or other language

This is the file header with your identity:
<?xml version="1.0" encoding="utf-8"?>
(<?xml-stylesheet href="rss.css" type="text/css"?> to add a CSS style)
<feed xmlns="">
<title>Atom feed of the site</title>
<link rel="alternate" type="text/html" hreflang="fr" href="" />
<link rel="self" type="application/atom+xml" href="" />
<subtitle>The last articles of</subtitle>


Then each article must appear on that model. If the articles are in a database, a request and a loop, and it's done. :-)
<title>Title of my article</title>
<link href="" type="text/html" />
<summary type="html"><![CDATA[Excerpt of the article...]]></summary>

To "summary" we can add a "content" which will be more complete, even the entire article if you're not affraid the readers don't be forced to come to your site to read it entirely (i.e. if you don't have ads on your site!). :-)

The link is written twice because "id" can be a diffrent identifier, but the simpliest is to put the link. It allows RSS readers to easily identity the readen posts.

More options are of course available, see all Atom specifications.

You must only pay attention to the dates format, a bit strange (normalized by the W3C). The rest is very close to RSS 2.0.


Be careful, you must send it with the good MIME type (subject of a previous article on the MIME type for CSS and Javascript):

header('Content-Type: application/atom+xml; charset=utf-8');

You can finaly test your feed on Feedvalidator or the W3C validator (they are clones, the result will be inevitably the same on both).

cafĂ© Did this article help you? 
Buy me a coffee!

6 answers at “Switch from RSS to Atom feeds”

  1. 1
    guruz ( said:

    OK, but are there any REAL advantages except w3c-compliancy? Anything that is visible to an end user?

  2. 2
    David ( said:

    Honestly for all courant use, I must say no. Atom is very close to RSS 2.0.

    You will just be proud to participate to the effort of standardization of the web. ;-)

  3. 3
    guruz ( said:

    which of course is a good thing too =)

  4. Backlink from Images in PHP with GD2 - Azure Dev
  5. 4
    required said:

    benefit - image enclosures

  6. 5
    David ( said:

    Both RSS and Atom can have images.

Leave a comment (all comments are moderated, don't waste time with spam)

Azure Dev