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
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

Incredible Demos

  • By
    Scroll IFRAMEs on iOS

    For the longest time, developers were frustrated by elements with overflow not being scrollable within the page of iOS Safari.  For my blog it was particularly frustrating because I display my demos in sandboxed IFRAMEs on top of the article itself, so as to not affect my site's...

  • By
    Scrolling “Go To Top” Link Using Dojo

    One of the most popular code snippets of posted on my blog has been the scrolling "Go To Top" link snippet. The premise of the snippet is simple: once the user scrolls an element (usually the BODY element) past a given threshold, a "Go...

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!