Archive for September, 2007

On WordPress and Atom

Although WordPress defaults to RSS, I prefer Atom. Here is how I configured my WordPress installation to suppress RSS.

Huge Feed Icon

The Feed Icon

When you view this and other blogs in a modern browser, you should see a little feed icon somewhere in the browser. In Firefox 2.0.x, this icon appears in the “location bar” as they call it. In IE 7, the feed icon appears in a toolbar. For a default WordPress installation, clicking this feed icon takes you to the RSS feed. In my blog, it takes you to my Atom feed:

http://stuffthathappens.com/blog/feed/atom/

Making the feed icon work with Atom instead of RSS is very easy in WordPress. You need to edit header.php in your WordPress theme. (I’m assuming your theme is roughly based on the ‘default’ theme…if not, I suppose your PHP file might be called something else). At any rate, simply replace the existing RSS <link> tag with this:

<head>
  ...
  <link rel="alternate" type="application/atom+xml"
      title="<?php bloginfo('name'); ?> Atom Feed"
      href="<?php bloginfo('atom_url'); ?>" />
  ...
</head>

That’s easy! And the results are instantly visible when you reload the page in your browser. Now, on to the footer.

The Footer

Scroll down to the bottom of any page on this site and you’ll see links to my Atom feed and my Atom Comments feed. The relevant PHP code is found in footer.php. Here is what I changed my footer to:

<p>
  Australopithecus afarensis (a.k.a. "Lucy") reads
  <cite><?php bloginfo('name'); ?></cite> every day via the
  <a href="<?php bloginfo('atom_url'); ?>">Entries</a>
  and <a href="<?php bloginfo('comments_atom_url'); ?>">Comments</a>
  Atom feeds.
</p>

Again, this is a piece of cake. Basically just search through your theme’s PHP files, replacing ‘rss’ with ‘atom’.

A Missing Feature

WordPress also gives you the ability to subscribe to comments for a particular post as RSS, but not (that I know of) as Atom. I found this code in single.php:

...You can follow any responses to this entry
through the <?php comments_rss_link('RSS 2.0'); ?> feed.

I tried changing that to comments_atom_link but had no success with that. So ultimately, I eliminated that from my blog.

Redirecting Away from RSS

After replacing or removing all RSS references from PHP files in my custom theme, I still had to find a way to keep people from navigating directly to an RSS feed. These are built-in to WordPress, so I had two options:

PHP Hacks?
  • Edit PHP files in WordPress
  • Redirect users by editing .htaccess

Editing PHP files is a Bad Idea. That’s because up until this point, all of the PHP editing I’ve done has been in my custom theme. To really remove RSS, you need to hack up WordPress itself. This will cause Bad Things when you try to upgrade to the next WordPress release.

Instead, I opted to edit .htaccess.

This file is found in the WordPress installation directory. If you’ve never heard of .htaccess, do a quick Google search for terms like “WordPress” and “.htaccess” to learn more about that. Here are the specific lines I added:

# Redirect RSS people to the Atom feeds
RewriteRule ^feed/$ /blog/feed/atom/ [R,L]
RewriteRule ^feed/rss/$ /blog/feed/atom/ [R,L]
RewriteRule ^feed/rss2/$ /blog/feed/atom/ [R,L]
RewriteRule ^comments/feed/$ /blog/comments/feed/atom/ [R,L]
RewriteRule ^comments/feed/rss/$ /blog/comments/feed/atom/ [R,L]
RewriteRule ^comments/feed/rss2/$ /blog/comments/feed/atom/ [R,L]

I’m sure I can make that shorter with some regular expressions, and I still think you can get to the RSS feed by entering the URL of the .php file directly. But for the most part, people who enter the most common RSS URLs are now greeted with an HTTP redirect that takes them to the “offical” Atom feed.

Why, Oh Why?

Because this is my blog and I prefer Atom. I prefer Atom because I’ve read both the Atom spec and the RSS spec, and I’ve written tools that produce and consume both types of feeds. Atom is clearly specified while RSS is ambiguous. When writing tools that produce syndication feeds, Atom allows you to clearly indicate if a “<” character is part of an HTML tag, an XML tag, or just plain text. That alone is enough reason to prefer Atom for information exchange.

When given a choice, I will always choose Atom over RSS.

Fresh Start

Since people started commenting within minutes of me installing WordPress with a dummy Lorem Ipsum post, I figured I’d better get this started for real.

Reset Button

My blog is back but the old content is not, nor will it ever be. I was not happy with the quality and it lacked focus. Hopefully that will change this time around.

If you want to subscribe, please use the Atom feed. I will completely disable any RSS feeds, even if I have to modify WordPress.

That’s all for now. Please let me know if you see any problems with this theme in your browser!