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.
<?php
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!
53 Responses
Héhé, merci pour le lien
Du coup je m’abonne !
I don’t think this works for Atom feeds however. I’ve tried to modify feeds by hooking the_content_rss and not had my functions executed. If you look in feed-atom.php, it calls the_content, not the_content_rss. feed-rss.php appears to correctly use the_content_rss.
@Julien: Merci à toi pour cet excellent article!
@King Rat: I didn’t tested it with Atom feeds, only rss. I’ll take a look
Has anyone tried this? Is there any working demo?
Thanks in advance!
Thank you for the great recipe! Tried to look for this a long time.
I tried this, and actually it works.
But I get this error message:
Warning: Cannot modify header information – headers already sent by (output started at /home/edwinp/public_html/wp-content/themes/flashnews/functions.php:548) in /home/edwinp/public_html/wp-includes/feed-rss2.php on line 8
Any suggestion how to fix this?
I think feedburner can easily put your adsense ads in your feeds…. this is perfect to those who do not use feedburner
@Edo: Weird…I didn’t had the problem so I can’t help you, sadly
@Popular Technology: Yes, feedburner can put adsense in your feed, but this recipe should help if you want to include other ads as such as affiliate marketing ads, for exemple.
@Popular Technology
You can also use this trick to insert a copyright.
@Edo
It is an encoding problem. We must save the functions.php in utf-8 without BOM (sometimes done to save through the theme editor repair the problem)
Ps: Sorry for the automatic translation
Is this better than using a plugin for putting a text of line in the rss-feed?
@Kaj Rietberg: It is basically the same effect. It mostly depends if YOU prefer using a plugin, or play with code
Thanks Man
but still ads is not showing up !!
What is the plugin that do similar effect that would you recommend? I tried to save the function.php in utf-8, still doesn’t work
not working for me…
input this to my functions.php
function insertAds($content) {
$content = $content.’ads link’;
return $content;
}
add_filter(‘the_excerpt_rss’, ‘insertAds’);
add_filter(‘the_content_rss’, ‘insertAds’);
@muhammad hakim: Do it works for you if you use the sample code I have provided?
@muhammad hakim
Seems that the filter don’t work on WP 2.5. There’s a bug in WordPress core. To avoid the problem, try something like this:
function gopostrss($content) {
if(is_feed()){
$content = ‘text before content’.$content.’ and after the content !’;
}
return $content;
}
add_filter(‘the_content’, ‘gopostrss’);
Ps: I added this hack on the original source
I tried the code in the post, and it didn’t work. Then I tried julien’s code, and it worked! Thank you julien!
@Betty: Yes, seems that there’s a bug in WP 2.5 and the code didn’t works. Glad Julien’s help was useful to you!
)
(Nice gravatar, btw
@Jean-Baptiste Jung:

Perhaps not only a bug in WP 2.5, because I’m using WP 2.7 now.
You gravatar is very cute, too.
BTW: I wrote a post about it and sent a trackback to here, but the trackback is not appearing…
I think this is a great script. It is work for WP 2.7 ?
@Busby SEO: Yes, it does
Hi Jean,
Thanks for your confirm.
Hi,
that looks slick. Can I add picture rather then a text link as an add.
Any hints how the code has to look like ?
I use wp125-ad-plugin-wordpress to dispaly my ads in the blog and WP 2.7
Thank you in advance
icewalker
@icewalker: Sure you can, just use the <img tag.
thanks for this tip, how do I get ads to show up in my comments RSS feed?
thanks
can’t get it to work at http://www.marcoraaphorst.nl/feed/ maybe because of Feedburner?
thanks to share this info. i never think about this before ( we can add ads on RSS feed)
great, i’ll use your trick to add my adsense ads on my RSS.
Trackbacks: