Insert ads on your wordpress RSS feed

November 13, 2008 · Print This Article

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.

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.

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');
?>

That’s all, your rss feeds now displays your ads.

If you have problem while using the code above, try that one:

Simply paste the following code on the functions.php file from your theme. Create that file if it doesn’t exists by default.


function insertRss($content) {
if(is_feed()){
$content = 'text before content'.$content.'<hr /><a href="http://www.wprecipes.com">Did you visited WpRecipes today?</a><hr />';
}
return $content;
}
add_filter('the_content', 'insertRss');
 


Related articles:

Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.