Half-a**ed Adsense

May 18th, 2008. Tagged: WordPress

It's official, I switched to the dark side. Not only does this blog has ads but they are Google's adsense. But hey, you gotta try.

Because I was so hesitant and have been postponing this moment for years, I only did it half-way. I added a condition - only show ads when displaying a single blog post and if the post is older than 30 days. This way if you follow this blog regularly by RSS or any other way, you won't see ads when posts are published.

So here's the code in case it's useful for someone. The code is not a wordpress pluggin, I only modified the "Single page" template.

// 1/2-ass adsense
if (time() - strtotime($post->post_date) > 30 * 24 * 60 * 60) {
  <div style="float: right; padding: 20px">
  <script type="text/javascript"><!--
    google_ad_client = "pub-8608773432853916";
    /* 250x250, created 5/18/08, first phpied test */
    google_ad_slot = "4896717118";
    google_ad_width = 250;
    google_ad_height = 250;
  <script type="text/javascript" 
} // end adsense

Basically it's the adsense-generated code wrapped in a div so I can float it and then wrapped in a condition that compares today's timestamp with the post's date.

Let's see what happens, maybe tomorrow I'll wake up rich. Or famous. Or both. 😀

Tell your friends about this post on Facebook and Twitter

Sorry, comments disabled and hidden due to excessive spam.

Meanwhile, hit me up on twitter @stoyanstefanov