How To Blend your AdSense Block within the WordPress Post Content?

A few weeks ago, when I (neatly) blended my Google AdSense 336×280 block a couple of paragraphs down the post content I thought I did a smart job! As a matter of fact, this was really resulting in an increased CTR (Click-Through-Rate) as well and a few readers like Hussein were interested in knowing how I went about doing it? (comment)

However, a few other regular readers like Kim, Lax and Mitch had altogether different views on this topic. Out of their conversation in my last post it was obvious that the regulars who read your blogs on a daily basis (fresh posts that is) should not be presented with the ad block in between though it’s okay for the older posts (seen mostly by search & referral visitors). Now, the following code sample(s) explains how this was achieved.

How to insert ad block for Older Posts alone?

Here, I am talking about inserting ad block in your single post view only and hence you can use this piece of code in single.php file of your theme and nowhere else. Now, if you want to display your ads for only those posts older than say 7 days, I would use the following code (code text file):

Code to display ads only for older posts

You can change the value 7 to anything else like 10 or 30 so that the ad gets displayed on those posts older than 10 days and 30 days respectively.

How to insert the ad block well into the post?

Now if you want to display an ad block after, say, the third paragraph of the post, the following is what you could do:

Withing the single.php, locate the code string the_content. It should look something like the image below:

single.php post rendering before commenting!

Now comment the whole line and include a new little module (yet to be written though we already call it single_post_split.php) below the commented code. The code portion within single.php will now look like:

single.php now includes single_post_split.php!

Add a file by name single_post_split.php to your theme folder and paste following code in that file and save it (Download the actual code from the following text file and rename it with .php extension)

single_post_split.php filled and saved!

This will now make sure that your ads get displayed after the third paragraph of all single posts that are older than seven days. If you don’t want the older post restriction, just remove the relevant condition in the ‘if’ statement.

You can add more such conditions to insert ad blocks at multiple locations within the post in conjunction with more styles to float them to left, right etc. Another sample code can be found here that displays a 250×250 ad block floated to the right after the first paragraph and a large rectangle ad block after the fifth paragraph.

It is also possible to implement conditions such as inserting ad for all posts except the last two or three etc but more such code could affect the performance of your blog rendering.

A Word of Caution

Back up your single.php theme file before attempting any modification to your theme code.

Comments

  1. Hi Ajith – This is a great, and informative post. This is a wonderful way to improve the click through rate.

    Barbara Swafford – Blogging Without A Blog’s last blog post… When Your Truth Is Different Than Mine

  2. Simply Good tip this is.

    How to alter the adsense code? I saw many of the sites like labnol.org, they will change the code to keep ads in b/w posts..but until you see clearly you can’t detect that ads are there…

    That is how they gets $$$ :)

    TechZoomIn’s last blog post… TechZoomIn Goals Set for the Year 2009

  3. @Barbara, I appreciate your compliments :)

    @Lax, thanks. Altering AdSense code is against their ToS and such sites will be banned. But Google AdSense also have AdSense API (Beta) that can be used to customize the look and feel of the ads, the way you want it and camouflaged. Unfortunately, this service is available only for AdSense publishers with a minimum of 100,000 page views per day!

    Using AdSense API only sites like moneycontrol.com makes a few lakh rupees per month. Have you seen the way they have blended the ads along with their services and other links? Superb it is…

    If you are interested in reading about AdSense API, please visit this link http://code.google.com/apis/adsense/

  4. Hussein :

    Before anything else, thanks for mentioning my name.

    Oh man! You just have had answered my question! I still need to edit some of my post.

  5. Ajith… BIG THANKS! I just needed that. I recently moved from blogger to wordpress and was looking for something just like this to increase my adsense clicks. Thanks you. I will be linking back to this post tomorrow in my weekly top 5 favorite posts section on sunday.

    Kurt Avish’s last blog post… Free Christmas Party Tickets!!

  6. Chetan :

    This trick is really cool, and many webmasters are using it.

    I recommand you to give Direct code to copy paste, rather than giving those images, images are not clear…

    Chetan’s last blog post… Mumbai Terrorist Attack – Now whats the future of TAJ and Oberai ?

  7. Chetan :

    One more thing, Calling too many function in your wordpress page is not a good idea, if you are using shared hosting this many cause high CPU usages, so use direct ad code rather than calling pages through functions.
    Else use WP-Super cache.

  8. @Hussein, no problem buddy…

    @Kurt, thank you very much and I hope you will increase your click-throughs with this trick. And great to know that this little tip is already in your faves.

    @Chetan, I have already linked the blocks of code that are more than one or two lines. One-liners should be typed in by you :) And thanks for the performance tips. Since I am running this code for sometime now, I know there’s no visible performance problems yet..

  9. Dennis Edell :

    Very cool codes; I will be sure to save and look this up again if i go back to using adsense. :)

  10. @Dennis, thanks… In fact, there are a number of such customizing I have done on various pages but writing about it and documenting is the pain πŸ˜†

  11. Nihar :

    Great tutorial. i have edited single-post.php for inserting ads but it was between title and post but not like this.

    Thanks again. i will implement this and see how is the CTR? whether it improves or not.

    Nihar’s last blog post… Take BEFolks First Grand New Year contest and Win Prizes!

  12. @Nihar, thanks… My CTR improved by at least 50-60% after the AdSense was injected into the post paragraphs. However, after some feedback from regular readers I took it out from the latest posts. But it works like a charm!

  13. Mitch :

    Wow Ajith, I hadn’t ever thought about popping it into articles by adding something to one of the php codes. I’ve been doing it the harder way, individually, but to tell you the truth I’ll probably stick to that because it allows me to pick and choose which articles to add it to, and which ones to leave alone. For instance, it wouldn’t do me much good to have it on a post with only one paragraph and a video, which I’ll do from time to time. Great going, my man!

  14. @Mitch, thanks man. I understand your requirement. I think for better control for selected articles, it’s better to do it the manual way…

  15. det :

    this is an awesome piece of advice!!

    i was looking for this, so far it’s working, let’s hope it continues like this!!

    thank you!!

  16. Raju :

    This is really cool tip Ajit. But I wonder if this can be done by any plugin. Odcourse its better to self-code rather than use plugin, but its a nice headsup for those coders to code a plugin which does this πŸ˜€

    Raju’s last blog post… 45 Awesome Websites to Watch Online TV for FREE!

  17. @Det, good to know that the tip was useful for you :)

    @Raju, thanks Raju. In fact, I thought of making this a plugin but realized that for each and every small thing if you start creating plugins that may affect the overall runtime performance of WP blogs.

  18. I think it is better to remove the

    <!– –>
    ..

    If the code is there, I usually get an error.. But after deleting it.. Everything works fine.

    Hussein’s last blog post… SplendidKid: @PeiProfit So that’s Step 3 is really required?

  19. @Hussein, probably your theme code has a different logic… It was working for me and I actually cut-pasted the code here :) Anyways, good to know that you got it working with that change… cheers!

  20. @ Raju
    this can be done with the help of adsense manager..but I’m unsure if you can achieve something like putting ads on posts older then 7 days with adsense manager.

    @Ajith
    Great post..every time I come here…I’m falling in love with your blog. :)

Trackbacks

  1. […] colour for the ads. Avoid yellow! It make you ads appear too artificial! Just be creative when you blend your adsense ads. Its all about colour […]

  2. […] This website has the instruction needed to insert the Google AdSense ad unit into the WordPress Post Content page. […]

Speak Your Mind

*