Welcome to our “RSS Tricks” series of tutorials! We’re going to be posting a new RSS-related tutorial every week for the next 8 weeks, so here it goes.
In this tutorial we’ll be showing you how to insert ads, or anything else for that matter, into your RSS feed.
This method will enable you to monetize your site by inserting any adverts or other content into your RSS feeds without having to touch any core files. It can be a good way to promote certain products or services, but use it wisely. Adding too many ads (or any other unrelated content) could put off subscribers.
The Fix
All it takes to insert new content into your RSS feed is to add a few lines of code to your theme’s functions.php file. If your theme doesn’t have one, you can create it yourself.
So once you’ve opened the functions.php file, just add in the following code:
<?php function insertAds($content) { $content = $content.'<hr /><a href="http://www.wpmayor.com">Have you visited WP Mayor today?</a><hr />'; return $content; } add_filter('the_excerpt_rss', 'insertAds'); add_filter('the_content_rss', 'insertAds'); ?>
That’s it. Your RSS feed now displays the ads you chose.
How It Works
Let’s go through this bit by bit.
First we created a new function called insertAds() , inside which we concatenated the HTML of the actual advert we want to include in the RSS feed to the $content variable (which contains the original content of the post).
Next we just use the add_filter() function to add our newly created insertAds() handler to the the_content_rss filter . The same is done for the the_excerpt_rss filter too.
Source: WP Recipes
Related resource: How to monetize your site without AdSense
6 Responses
I noticed when adding links using this code, the links don’t work in Mad Mimi. Works in Feedburner and MC fine.
Thanks for letting us know Brad. I hadn’t heard of Mad Mimi before but I’ll check it out.
Mark
I’m not a techie, where exactly do I place the adsense code?
Thanks !
Hmm, good idea but the problem is this.
When I insert an ad with this method the ad gets appended to every post on the rss feed. Which is a bit annoying for the subscriber.
I thought it would be like, every 3rd or 4th item in the feed would be an ad. I wonder if there’s a way to do this?
Hey Talha, I’m not sure how to do this myself, but if you do find a way to do it please feel free to share it with everyone here. I can then update the post above too.
You may want to contact our friends at Codeable too, they can help you out with this. This form goes directly to their team: https://www.wprssaggregator.com/customization/