Making Your RSS Feeds Sexy With Custom Content In WordPress
Adding text and images to your feed
This is a basic function you can paste into your functions.php, and easily add custom content to your RSS feed when using WordPress. What this does is first check to see if it is the feed is_feed(), and if it is the feed, then it creates a variable called $content.
This variable is where you can add your custom text, images, or anything at all, as long as somewhere within it is the function call to the_content() like I have here after the logo image for New2WP. Notice that I use the single quote period before and after the function: ( ' . the_content() . ' ). This is to properly concatenate the variable since the function is Php.

After this variable it will return it, thereby displaying it in your feed as the_content() which should be shown.
function insertRss($content) {
if( is_feed()) {
$content = '<a href="http://new2wp.com"><img src="http://new2wp.com/wp-content/themes/New2WP/images/new2wp-logo.png" alt="New2WP - A Resource for WordPress Tutorials, Tips, Tricks and More!" /></a><br /><br />
TEXT BEFORE CONTENT' . $content . '<a href="http://new2wp.com"><img src="http://new2wp.com/wp-content/uploads/2010/06/new2wp-468x60px.png" alt="New2WP - A Resource for WordPress Tutorials, Tips, Tricks and More!" /></a>';
}
return $content;
}
There's several ways you could do this differently
For example, you could set the_content() as the value of a variable prior to this, say $thecontent = the_content();, and then when you create the $content you can use double quotes around your content like:
$content = "THIS IS CUSTOM STUFF BEFORE $thecontent THIS IS CUSTOM STUFF AFTER";
This will work the same way since variables within double quotes in Php will parse the value that they are equal to. Using single quotes here, however, will just display the text $thecontent, since single quotes parse the literal variable and not what the variable equals.
Don't forget to add the filter
add_filter( 'the_content', 'insertRss' );
Finally, to make this complete and properly display your custom content in your feed, you need to add the hook to WordPress that makes it work and run as it should. So make sure to add the above filter to your functions.php file along with the function.
That's all there is to it. If you have any questions let me know in the comments.
To take this even further, learn how to add post thumbnails to your feeds, to add even more customization.






User Comments
( ADD YOURS )euantor July 5
Take it you can use a similar method to apply CSS styling? Or, am I completely mistaken?
euantor recently posted..Nintendo Pros goes iPhone friendly
Jared July 5
Well yeah I supposed you could, at least for those that subscribe via email. Not sure if RSS readers understand CSS code well, if even at all. I doubt that the do, never used any of them so idk.
But, as far as those that subscribe to the RSS by email, there is a LOT of things that go into email and how all the various email clients render the code that they are able to accept. To make it work across all email clients is an extremely huge pain in the ass, and I really honestly wouldn't even bother with adding CSS to your RSS feed. If you were using a 3rd party email service you then have much more control over the code that gets output. But that's another thing altogether.
So no, you probably couldn't/shouldn't bother trying doing that.
euantor July 5
Hm. Okay then. Just thought it would be cool really haha
euantor recently posted..Epic Mickey “Merges Mario and Zelda”
Jared July 5
Yeah, I hadn't really thought about doing that, but now I'm kinda curious how hard it would be.
I mean, I was able to completely transform the wordpress dashboard to match the theme of this site http://new2wp.com/pro/wordpress-dashboard-themes/
I'm going to try it out, and see what the deal is with it. I quickly looked at the code the RSS outputs in my email so I know i could find a way to alter/override that somehow, but I'd probably have to do a conditional to only do it to the feed IF its the email rss.
Trackbacks