Enabling Full Feeds for WordPress 2.0+

After I’d moved Make Easy Money with Google and AdSense to WordPress, one of my readers complained that he was getting only a partial feed in his RSS reader. This was odd since I had enabled the full feed option when I configured the blog. After some digging around, I discovered why this was happening, and I’m presenting the information here in the hopes it will help others with the same problem.

How Feeds Are Generated

The problem lies in the way the RSS 2.0 feed is constructed. In WordPress 2.0 and 2.1 there’s a file called wp-rss2.php that is executed to generate the feed. In WordPress 2.2 the code’s been moved to the file feed-rss2.php in the wp-includes folder. Both files are essentially the same, however.

The problem lies in this fragment of code extracted from the feed generation:

<?php if (get_option('rss_use_excerpt')) : ?>
    <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
    <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
  <?php if ( strlen( $post->post_content ) > 0 ) : ?>
    <content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>
  <?php else : ?>
    <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]>
    </content:encoded>
  <?php endif; ?>
<?php endif; ?>

Translated into English, this is what it says:

If the option is set to use excerpts then
  Set the <description> tag to be the excerpt
Else
  Set the <description> tag to be the excerpt
  If the post is not empty then
    Set the <content:encoded> tag to the full content
  Else
    Set the <content:encoded> tag to the excerpt
  Endif
Endif

Actually, the logic above is unnecessarily complicated. I’m not sure why it wasn’t written to work like this in the first place:

Set the <description> tag to be the excerpt
If the post is not empty then
  Set the <content:encoded> tag to the full content
Else
  Set the <content:encoded> tag to the excerpt
Endif

But that’s neither here nor there. The problem we’re after lies with the use of the <description> and <content:encoded> tags.

What’s a Description?

An RSS feed mostly consists of a series of item definitions. This is what the RSS 2.0 specification says about items:

An item may represent a “story” — much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed; see examples), and the link and title may be omitted.

So either the <description> is a summary of the text of the item or is the complete item text itself. So far so good — this is what we want to see in our feeds, either summaries or the full text. So what is the <content:encoded> tag’s place in all of this?

It’s historical. Originally, the <description> tag was only supposed to contain plain text content. No HTML markup, in other words. The actual HTML markup was placed in a separate tag called <content:encoded> as described here. And that’s what the default feed generation code for WordPress does. But the RSS 2.0 specification allows HTML markup in the <description> tag as long as it’s properly encoded — that’s what the paragraph I quoted above mentions. But <content:encoded> is still used by WordPress.

Readers Are Inconsistent

The problem is that not all RSS readers handle the <content:encoded> tag properly. Some readers always show a partial feed — the content of the <description> tag. Some show the full content if they find the <content:encoded> tag in the item.

The simplest way to fix this problem is to remove the <content:encoded> tag from the RSS 2.0 feed and include the full text in the <description> tag. Do this by replacing the code shown above with this fragment:

<?php if (get_option('rss_use_excerpt')) : ?>
    <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
    <description><![CDATA[<?php the_content('',0,'') ?>]]></description>
  <?php endif; ?>
<?php endif; ?>

Copy the changed file up to your blog and post something. You should see a proper full feed appear if you’ve set the full feed option.

Full or Partial?

Of course, this only matters to you if you believe in providing full feeds in the first place. If you prefer partial feeds then don’t do anything — the default WordPress behavior suits you fine.

You might think that as an AdSense publisher I’d recommend you use partial feeds. But I don’t. Yes, this costs me money because readers don’t click through to my site and see the AdSense ads. (Well, not my AdSense blog, its readers are pretty jaded and stingy!) But they still read my content. And once Google is done integrating FeedBurner into the fold I’m sure some new feed monetization options will open up for AdSense publishers. Ultimately, though, it’s a decision that AdSense publishers have to make for themselves. Personally, though, I think that you should use full feeds if your feed is meant for humans — if you’re looking to increase your readership. If you’re publishing feeds primarily as a way to get your content indexed then partial feeds will work fine. Again, only you can decide what’s right for your site.

Technorati Tags: , , , ,

Sponsored Link: For a complete set of AdSense best practices, read Uncommon AdSense — for serious AdSense publishers only!

Eric Giguere is the author of Uncommon AdSense and the award-nominated (that just means it lost!) blog Make Easy Money with Google and AdSense.

Socialize This Post (Please!)

Add to OnlywireAdd to Onlywire

Tags

Comments

3 Responses to “Enabling Full Feeds for WordPress 2.0+”

  1. Publishing Full Feed RSS with WordPress » Really Smart Guy » GeekSpeak, Real Estate, Landlording, Technology, Business Ideas, Web Marketing » Blog Archive on June 7th, 2007 12:42 pm

    [...] the very same day, my friend Eric Giguere published an article on his AdSense blog about publishing Full Feed RSS on WordPress 2.0+. He actually dug into the code and hacked it to display the entire feed within the RSS description [...]

  2. Staska on June 8th, 2007 5:00 pm

    There’s much easier way to get full feeds for us, who do not know much about php and just want our blog to work.

    It’s full feed WP plugin by CaveMonkey:

    http://cavemonkey50.com/code/full-feed/

    Works like a charm and you just need to install it, no php editing required

  3. Eric Giguere on June 8th, 2007 7:41 pm

    No, that plugin (and there are at least two others out there like it) fixes a different problem, which is that WordPress cuts the feeds off when it sees the “more” sequence in the posting. But none of my postings have that anyhow. This fix is different.

Subscribe without commenting