Multiple versions of RSS feed? One with full content, one with the excerpt

I’m not sure how to word my question and I have been searching all day, to no avail.

I am looking for a method to create two versions of my RSS feeds, one with the full content and one with only the excerpt.

Mainly, I want to do this for the “Author” feeds. I would like two feeds created for each Author. One with the full content and one with the excerpt. If nothing else, I would like the author RSS feed to only have excerpts, but the main website RSS feed must ALWAYS be a full content feed.

The reason? The website in question is a sports website. I want to offer the RSS in full content for those who want it, but I also automatically post my own articles on my personal website (a few others do as well). When the article is posted to my own website, I want to only include the excerpt, with a link to the full original article.

I do not care the method used, whether code or plugin.

UPDATE

I have been working to try to get the methods described by Michael Ecklund and Ian Dunn to work. I have not been able to get either to work. Both methods still show the complete article in the RSS feed and not the excerpt.

I’m not sure if it makes a difference, but I just remembered I use the Advanced Excerpt plugin to manage the excerpts on my website. I have not tried disabling this plugin, as it controls the homepage, category pages, tags pages, author pages and more.

4 Answers
4

My approach would be to:

  1. On the Reading Options page, set the For each article in a feed, show... option to Full Text so that, by default, feeds will include the entire post.
  2. Pass a custom URL parameter to each individual feed when you want the excerpt instead of the full text. e.g., http://example.com/author/username/feed?format=excerpt. Make sure you don’t use a reserved term for the parameter name.
  3. Hook into the feed creation process and modify the content based on whether or not the custom parameter is present in the current feed’s URL.
  4. If it is present, override the feed’s content to only display the excerpt instead of the full text.
  5. When you want the full content, just use the regular URL. e.g., http://example.com/author/username/feed.

Here’s some code that does that, using format as the parameter name. You can use any parameter name you want, as long as you update each part of the code that references it. Put the code inside a functionality plugin.

function truncateFeedContent( $content )
{
    if( get_query_var( 'format' ) == 'excerpt' )
    {
        $content = get_the_excerpt();
        $content = apply_filters( 'the_excerpt_rss', $content );
    }

    return $content;
}
add_filter( 'the_content_feed', 'truncateFeedContent' );

function addFormatQueryVar( $queryVars )
{
    $queryVars[] = 'format';

    return $queryVars;
}
add_filter( 'query_vars', 'addFormatQueryVar' );

To avoid a conflict with the Advanced Excerpt plugin, add this code to the functionality plugin as well. It will disable Advanced Excerpt’s functionality on feed URLs, but leave it in tact for all other pages.

function stopAdvancedExcerptOnFeeds()
{
    if( is_feed() )
        remove_filter( 'get_the_excerpt', array( 'AdvancedExcerpt', 'filter' ) );
}
add_action( 'pre_get_posts', 'stopAdvancedExcerptOnFeeds' );

Leave a Comment