Append and Prepend to WordPress RSS Feed Content

By  on  

The awesome part of RSS is that it lets you pull content wherever you want.  The bad part, as a publisher, is that the user may be missing out on important information that is on the site but doesn't display in articles.  WordPress' hook system to the rescue!

The PHP

We're going to hook onto the the_content and the_excerpt_rss function hooks to append or prepend content to feed entries:

// Additional RSS Content
$rss_more_content = 'blah blah blah';
$rss_more_position = 'before'; // or "after"

// Function which adds content to RSS entries
function add_rss_content($content) {
	global $rss_more_position, $rss_more_content;

	if(is_feed()) {
		if ($rss_more_position == 'before') {
			$content = "

$rss_more_content

\n$content"; } else { $content .= "

$rss_more_content

\n"; } } return $content; } // Add hooks add_filter('the_content', 'add_rss_content'); add_filter('the_excerpt_rss', 'add_rss_content');

The only conditional is whether or not you want the content added at the top or bottom of the content block.  This function should go into your functions.php file, but how you pull in the additional content in is up to you!

Recent Features

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

  • By
    Camera and Video Control with HTML5

    Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API...

Incredible Demos

  • By
    Google Font API

    Google recently debuted a new web service called the Font API.  Google's Font API provides developers a means by which they may quickly and painlessly add custom fonts to their website.  Let's take a quick look at the ways by which the Google Font...

  • By
    MooTools HTML Police: dwMarkupMarine

    We've all inherited rubbish websites from webmasters that couldn't master valid HTML. You know the horrid markup: paragraph tags with align attributes and body tags with background attributes. It's almost a sin what they do. That's where dwMarkupMarine comes in.

Discussion

  1. You discuss good points about WordPress RSS Feed Content that is useful code for wordpress developers. Thanks to share such useful code with us.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!