Textpattern + some plugins = broken feed

Dec 13, 11:18 AM

broken feed

I’ve read quite a bit about Textpattern’s annoying habit of creating RSS/Atom feeds that browsers download instead of display, because I’m relatively new to Textpattern and was experiencing the same problem. It turns out that the problem is in the plugins, kids. I’m sure a lot of you already figured this out, but knowledge unshared is only useful to one person. So I shall share my (mercifully brief) RSS odyssey.

broken how?

First off, I think I should define the problem before I explain my solution.

The feeds that are generated by Textpattern “out of the box” are of the MIME types “application/atom+xml” and “application/rss+xml” (depending). These feeds work fine and dandy right after you’ve successfully installed Textpattern. Take a closer look at the source of one of these feeds. The very first line should look something like:

<?xml version="1.0" encoding="utf-8"?>

Note that the “<” in “<?xml” should be the first character in the file.

Now take a broken feed – one which you’re prompted to download instead of your browser displaying it (as is normally & should be the case, barring plugins, XML handling app’s, etc). Since I’ve already primed you on what to look for, you’ll notice that there is a space just before the XML declaration.

blame yourself

As I said, I’m new to txp. So naturally my first thought was that one of the custom plugins I’d written for my site was the culprit. At the time I had them in a ‘plugins’ directory, so I simply removed them, then removed all mention of my custom tags from all pages and forms. ‘Went to my feed: same thing. Stupid space.

blame the Maker(s)

So being the PHP dork that I am, I decided that the problem must be in the Textpattern code itself. My reasoning was thus: I haven’t done anything truly earthshattering with my Textpattern install, and there was hardly anything worth finding in the Textpattern forum, to say nothing of their FAQ. There are two unhelpful FAQ entries related to feeds, but they weren’t very helpful and were written in a decidedly angry/defensive tone (and have perhaps unintentional factual errors):

I’ve tweaked quite a few open source projects over the years, so I dug through an entire trace of what goes into the serving of an RSS or Atom feed in Textpattern. What a magical odyssey that was. But to no avail: there was nothing I could find that would directly and obviously cause that damnable space. Does PHP’s eval function have a tendency to insert spaces? Not if the code being eval’d doesn’t, as far as I know.

blame others

So if Textpattern wasn’t to blame (at least not directly), and I wasn’t to blame, chances were that one of those dang plugins was doing it. And it was, though for the life of me I don’t know why. It happened to be the cbs_article_index that i had in my plugin cache directory in this case, but as it seems so many people have had an issue with Textpattern’s default feeds, I seriously doubt it’s just this plugin that’s the problem.

When in doubt, hack.

But this is where open source kicks gluteous. Good ol’ Noam Samuel has published a handy, dandy Textpattern feed hack. It’s specifically for RSS. Does anyone know if will work for the Atom feed, too? I sure don’t.


After some tinkering, I finally found the problem. The issue has to do with plugins in your plugin cache folder (commonly, textpattern/plugins).

For whatever reason, a space after the “?>” (end of PHP) ending or after any newline (\n) after the “?>” is resulting in a space being inserted before the intended first character of Textpattern output. So: the solution is to make absotively, posolutely sure that there is nothing after the plugin’s “?>” ending.

It seems that there’s a need for some clarification by Textpattern regarding best practices with plugins.

At any rate, I hope that this helps someone out there, and that some bright spark can figure out exactly what and where this is breaking. Happy blogging.

12/14/07 Update


That was fast. I put it on the Textpattern Forum (log in/register first to be able to see it) once I’d gotten it all figured out, and wet kindly fixed it within… minutes, seemingly. Squeaky wheel gets greased I guess.

Bookmark and Share


  1. You have been heard. Fixed, as I hope.

    Robert · Dec 13, 03:25 PM · #


Valid XHTML 1.1 Valid CSS
             © 2008, garvin