DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Did you ever wonder how some people are able to display ads on their rss feed? Sure, you can modify core files to do it, but that’s not a good idea at all. Here’s a clean way to insert ads (or anything) on your rss feed, without having to hack any core file.

In order to achieve this recipe, paste the code below to the functions.php file from your theme. If your theme doesn’t have a functions.php file, create it.

function insertAds($content) {
    $content = $content.'<hr /><a href="http://www.wprecipes.com">Have you visited WpRecipes today?</a><hr />';
    return $content;
add_filter('the_excerpt_rss', 'insertAds');
add_filter('the_content_rss', 'insertAds');

Here, we first create a function called insertAds(), which concatenate a code containing our advertisment to the $content variable, which contains the content of the post.
Then, we use the add_filter() function to overwrite the the_content_rss() function with our insertAds() function. We use another filter to overwrite the_excerpt_rss() function as well.
That’s all, your rss feeds now displays your ads!

Credits goes to k-ny for this awesome recipe!

One Comment

  1. Thanks for this. I’m testing it out on a site right now. The code was a bit different for a site built on the Genesis framework. But the general idea seems perfect.

Leave a Comment

Your email address will not be published. Required fields are marked *