Picture of Mark Zahra

Mark Zahra

Mark has been involved with WP RSS Aggregator for almost a decade, from running customer support to now leading RebelCode, the company behind the plugin. He has a passion for content and news, especially the concept of ethically sharing content to help each other grow.

Table of contents

Streamline your
content-sharing process

Get started with WP RSS Aggregator today and unlock the full potential of RSS feeds!

RSS Tricks: How to Insert Ads (or more) Into Your RSS Feed

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

Article by

Article by

Share the Post:

6 Responses

  1. Thanks for letting us know Brad. I hadn’t heard of Mad Mimi before but I’ll check it out.

    Mark

  2. 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?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles