RSS feed blog feed : : del.icio.us : : newsletter : : free magazines : : find a job

Hack for RSS Feed Ads

Posted by Ken Cheung on Tuesday, March 6, 2007 in How-to, WordPress : : 4 comments

I've been playing with the Better Feed WordPress plugin to insert ads in my RSS feed. As I mentioned previously, it's fairly easy to add a text footer or graphics ad into your feed. However, if you want to rotate between multiple ads, then you need to hack the plugin. Read on to find out how.

You will need to find the following line in the Better Feed plugin (if you have not added a footer or modified the plugin, it's around line #101):

$content .= wp_ozh_betterfeed_detokenize($wp_ozh_betterfeed['footer']);

I'm going to call it the "footer" line. Once you have found the "footer" line, you will need to add a block of code above that line. Something like:

[block of code]
$content .= wp_ozh_betterfeed_detokenize($wp_ozh_betterfeed['footer']);

I have put together three sets of block codes that you can use. Select the one that best suits your needs.

Block 1 - Alternate ads
This code block is for alternating ads in your feed. For instance, post #1 will show "Ad-B", post #2 will show "Ad-A", post #3 will show "Ad-B" again, post #4 will show "Ad-A" again, etc. Here's the block to insert above the "footer" line:

if ($id % 2 == 0 ) {
  $ad = "Ad-A";
} else {
  $ad = "Ad-B";
}
$content .= $ad;

Block 2a - Rotate between four ads
[2007.03.10 note: The random number generator used in this block can cause old posts to show up as "updated" in Bloglines. If you don't want this to happen, use Block 2b instead.]
This code block is for displaying one of four ads in your feed. For instance, post #1 will show either "Ad-C" or "Ad-D", post #2 will show either "Ad-A" or "Ad-B", post #3 will show either "Ad-C" or "Ad-D" again, post #4 will show either "Ad-A" or "Ad-B" again, etc. Here's the block to insert above the "footer" line:

if ($id % 2 == 0) {
  $num = rand(1,2);
  if ($num == 1) {
    $ad = "Ad-A";
  } else {
    $ad = "Ad-B";
  }
} else {
  $num = rand(1,2);
  if ($num == 1) {
    $ad = "Ad-C";
  } else {
    $ad = "Ad-D";
  }
}
$content .= $ad;

Block 2b - Rotate between four ads
[Added on 2007.03.10]
This code block is for displaying one of four ads. It's like the block of code above, but it uses the timestamp of the post instead of a random number generator. It shouldn't change an old post to "updated" in Bloglines. Here's the block to insert above the "footer" line:

$num = get_post_time('s');
if ($id % 2 == 0) {
  if ($num < 30) {
    $ad = "Ad-A";
  } else {
    $ad = "Ad-B";
  }
} else {
  if ($num < 30) {
    $ad = "Ad-C";
  } else {
    $ad = "Ad-D";
  }
}
$content .= $ad;

Block 3 - Display an ad for every 3rd, 6th, and 9th post
I use this code block for my news site. I write over 20 posts a day on that site and it would look too commercial if I ran a RSS ad in every post. This block of code will display an ad for every 3rd, 6th, and 9th post. Here's the block to insert above the "footer" line:

$ad3 = "Ad-A";
$ad6 = "Ad-B";
$ad9 = "Ad-C";
$num = substr ($id, -1);
switch ($num)
{
  case 3:
    $content .= $ad3;
    break;
  case 6:
    $content .= $ad6;
    break;
  case 9:
    $content .= $ad9;
    break;
}

You will need to replace "Ad-A", "Ad-B", "Ad-C", and "Ad-D" with the html code for your ads. Keep in mind that the code is already using double quotes. So, you will either need to use single quotes or omit the quotes in your html code for your ads. For instance:

$ad = "<p align=center><a href=http://www.embeddedstar.com/careers/><img src=http://edageek.com/adimages/jobs468.gif border=0></a></p>";

As you can see, I didn't use any quotes between the double quotes above.

One other note. WordPress assigns post id numbers in the order you saved them. The id numbers can get out of order if you don't publish your posts in the same order you saved them. This may cause the ads to appear to display out of sequence (ie - the same ad displaying two times in a roll). That is not the case.

free creative and multimedia magazines

Adsense 300×250 Ad Unit

Posted by Ken Cheung on Sunday, February 18, 2007 in Adsense : : 2 comments

Like ten million other publishers, I got an email from Google last month. In the email, Google suggested I place 300×250 Adsense units on my site. In exchange, they would include my site in their custom placement packs program. Custom placement packs are selections of individually reviewed sites designed for Google's largest brand advertisers. In other words, they want to show more video ads. I doubt video ads will work well on my site and I'm not too fond of running such a big ad in the content area. But I decided to do a test run on three of my sites. All three sites use the same theme (with different colors).

The results below are based on the first 16 days of January and February. In February, I ran 300×250 ads (top right of content) in place of 468×60 banners (above content in January). So "28%" for the 300×250 stat in the first table means the 300×250 ad resulted in an eCPM increase of 28% compared to the 468×60 ad I ran in January. Keep in mind I'm comparing stats from two different months.

January vs February eCPM for Site #1
Site #1 eCPM
300×250 (top right of content) +28%
160×600 (left side bar) +51%
Link unit (below header) -52%
Overall +24%
January vs February eCPM for Site #2
Site #2 eCPM
300×250 (top right of content) +70%
160×600 (left side bar) +16%
Link unit (below header) +19%
300×250 (bottom of content) -22%
Overall +25%
January vs February eCPM for Site #3
Site #3 eCPM
300×250 (top right of content) +16%
160×600 (left side bar) -13%
Link unit (below header) -10%
Overall -4%

As you can see, the 300×250 ads resulted in an overall increase for two of my sites. However, the medium rectangle ad resulted in a slight decrease for the third site, which happens to be my main site. I'm not going to pull the new ad size yet. I'm going to let it run a little longer to see if being included in Google's custom placement packs program makes a difference.

free ebook - Website Payments with PayPal

Upgrading to WordPress 2.1 Tip

Posted by Ken Cheung on Sunday, February 11, 2007 in How-to, WordPress : : one comment

I upgraded to WordPress 2.1 recently and I want to share a tip. I uncompressed the new WP 2.1 files into a new directory. I name it wordpress2.1 then I upload the entire new directory to my server. When I was ready to switch to the new version, I jus renamed the current wordpress directory to something like wordpress2.07. Then I renamed the new version to match the name of my official wordpress directory (ie - wordpress). This way, I have a clean install and I still have the old version to cut back to if something went wrong.

If you look at the WordPress upgrade instructions, it'll tell you to delete certain files and don't delete certain files. Seems kinda of messy to me. Below are the steps I took. Keep in mind my situation will be different from your setup, so you will need to modify the steps to suit your needs.

  1. Download and extract WP 2.1 to a new directory named wordpress2.1
  2. Back up the database by using the WordPress backup plugin or phpMyAdmin
  3. I made a change to template-functions-post.php in the old version of WordPress to alter the behavior of the more tag, so I had to make the change in the new version. In WP 2.1, I had to make the change in a new file called post-template.php.
  4. Copy the following files from the old WordPress directory to the new directory:
    • wp-config.php (it's in the root wordpress directory)
    • plugins (except Akismet because WP 2.1 comes with a new version of Akismet)
    • theme files
  5. Deactivate the plugins (don't forget to write down special codes, like the Akismet api key, in case you need to re-enter them after you re-activate the plugins)
  6. Rename the old wordpress directory (ie: wordpress –> wordpress2.07)
  7. Rename the new wordpress directory (ie: wordpress2.1 –> wordpress)
  8. Run the upgrade script (load …/wordpress/wp-admin/upgrade.php in the browser)
  9. Reactive the plugin one by one

Remember, the above steps are for my situation. You will need to look at the WordPress upgrade instructions and modify the above steps for your setup.

free eWeek

Bloglines Problem

Posted by Ken Cheung on Saturday, February 3, 2007 in FeedBurner : : comment

[Update: Bloglines fixed itself overnight. The problem does not appear to be related to CoolPlayer 9, WP 2.1, or FeedBurner 2.2.]

It appears the CoolPlayer 9 plugin may be causing problems with Bloglines. This is the error message I get in Bloglines:

Bloglines has encountered an error trying to fetch the latest version of this feed. Bloglines handles errors automatically, no action is required by you. The error was:

The feed does not appear to exist. This can be caused by the feed URL being incorrect, or it can be caused by a configuration issue with the server hosting the feed. If this error continues, you should check the feed URL and, if it is wrong, subscribe to the correct URL.

The plugin does not seem to affect the other RSS readers, like Google Reader and NetVibes. I'm posting this in case you are using Bloglines and didn't see my previous post on CoolPlayer 9. This is also a test for me. I'm guessing the problem is related to CoolPlayer 9. It could also be related to upgrading to WordPress 2.1 and FeedBurner 2.2 plugin. I'll know in a few minutes if I can see this post in Bloglines. If it's the plugin, hopefully it will only affect the post with the coolplayer tag and not all posts.

iZachy Newsletter

Don't have time to visit iZachy everyday? Then sign up for my free newsletter. I'll send you an email when I have something to share with you. Your email address will be kept confidential and I will not share, sell, or rent it to anyone. You can unsubscribe at any time by clicking a link in the email.

Enter your email address to sign up for my newsletter: