noizZze

WordPress: Feeds With Read More

Today I have discovered one very unpleasant thing about my syndication feed. I have a habit to make a post consist of two parts: the introduction and the actual content. Between these two parts I put “<!--more-->” mark and what you see on my title page is the list of introductions to the writings. This approach is quite popular among bloggers as it allows us to let users judge for themselves whether they are interested in the content or no before jumping into actual reading. What I have discovered today was that feeds I have contain full content and not the introduction part only. That was a surprise to me because I was working with B2Evolution and MovableType before, and they did what was expected – included introduction only. Reading further you can find out how I fixed that.

Quick scanning of community gave no responses to my question on how to force the WordPress to show only first part of post in the feed. I found the swich to output excerpts or full text only. While the excerpts were close to what I needed, they didn’t allow me to control amount of text I wish to put into the feed and that’s why could barely be useful. So I decided to spend no more time on searches and fix the feed production myself. Fortunately, it wasn’t very hard and here I explain what you have to do.

First, it must be you already know that WordPress provides means to generate four types of feeds (Atom, RDF, RSS, RSS2.0). If you are exposing all of them to your readers, you will need to change all four generation templates (wp-atom.php, wp-rdf.php, wp-rss.php and wp-rss2.php). The templates look very similar and there will be no problems with them. Let me update only one of them as an example – the most widely used RSS2.0.

When you open the template (wp-rss2.php) in text editor or WordPress internal editor you see the mix of XML and PHP. PHP is used to include dynamic contents into the static structure of XML.

Find the line near the top of the file telling “$more=1”. It says that we wish to output “more” part of the post to our feed. It isn’t true so change it to “$more=0”. Next, walk down to the line with “the_content('', 0, '')” text. This function call will output the text of post. First argument, which is empty string, tells the label of “more” link. Put some text there, like “Read complete post”, “Read more” or something else.

That’s all. Pretty simple, right? From now on your RSS2.0 feed shows only first part of the post (before “<!--more-->”) and your readers are happy.