Skip to main content

Insert Ads, Images or anything in RSS Feeds in WordPress

Monetizing RSS feeds has becomw a common practice, and many blogs do it to maximize their income. FeedBurner can insert AdSense ads into your feed items, but you need at least 500 subscribers to qualify, and you can’t use any ads other than the AdSense ads provided by FeedBurner. So what is the workaround? What if you want to show images in the feeds? Well thats quite easy!

Follow these simple steps to perform this hack:
  1. Edit the functions.php file of your theme. If your theme doesn’t have a functions.php file, simply create one.
  2. Paste the following code into your functions.php file:
  3. <?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'); ?>
  4. Save the file. You’re now displaying your ads in your RSS feed!
Code explanation. 
I have seen many similar hacks on the Web, but all of them require you to edit WordPress core files to achieve the same result. Of course, editing WordPress core files is a very bad idea because then you would have to re-edit the files each time you upgrade your blog. Instead, this hack uses the add_filter() WordPress function to insert content into your RSS feed without editing any core files.

Source:
SmashingMagazine

For any doubts or additions please do use the comment form.

Comments

Popular posts from this blog

Inserting post image programmatically to worpress

We have discussed how posts can be added programmatically before. This comes very much handy when you have to make custom scripts to import content from some cms especially custom ones. But the thing often missed is how to add post image for a particular post programmatically. This is something that is always missed. There very less resources online explaining this. But this is a very straight forward thing and very easy to do. There is this wonderful function that does this beautifully. media_sideload_image($url,$post_id,$description); The first argument is the remote url of the image you want to download. The second argument is the post id of the post to which you want to attach the image. The third argument is optional, but will be a description if included. I'd suggest finding a way to throttle the downloads so that you don't keep timing out, such as limiting the number of images it pulls in per load and setting the importer to refresh itself between dow

Add new avatars to your wordpress and Say Good-Bye to Mystery Man

If you are like most of the other wordpress developers out there, then you might also had this problem with the default mystery man in wordpress. You also would wanted to change the deafualt avatar of your comments with something nice. It's not that hard. It's infact very easy. Just add this to your functions.php file within your theme folder. /** * add a default-gravatar to options */ if ( !function_exists('fb_addgravatar') ) { function fb_addgravatar( $avatar_defaults ) { $myavatar = get_bloginfo('template_directory') . '/images/avatar.gif'; $avatar_defaults[$myavatar] = 'people'; $myavatar2 = get_bloginfo('template_directory') . '/images/myavatar.png'; $avatar_defaults[$myavatar2] = 'wpengineer.com'; return $avatar_defaults; } add_filter( 'avatar_defaults', 'fb_addgravatar' ); } Why this? When you can have this! Happy coding! For any queries or suggestions give a comment below!

Using WordPress Comment Meta

Comment meta is such a wonderful addition to WordPress that allow us to extend the native comment form with additional fields. This comes very handy for the one's who is trying to create review sites etc. Unfortunately there’s no documentation added on the WP codex. For the purpose of demonstration we will be doing: add a check box to the comments form. show in the WordPress comments admin whether or not the checkbox was selected. indicate in the comment notification email whether or not the checkbox was selected. Adding the checkbox to the comments form is easy. To add the checkbox to the comments form open up your themes comments.php file and paste this into the area where you need it: <label><input id="publishc" name="publishc" tabindex="90" type="checkbox" value="this is the value I want to capture" /> Whatever sentence that you want commenters to use the checkbox for</label> Now that the checkbox