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.


  1. Ajith, if you observe my blog single posts, you will notice that I use intext ads starting from 2nd paragraph – first paragraph is intentionally excluded. I use simple method to do this. Like any intext ad network even ET has section limiting and I use it through a plugin called “Blog Control” – and display the ads after the more break.

    Pavan Kumar´s last blog post… Free Website Monitoring Tools to Monitor Website Uptime

  2. @ Raju,

    Check out Who sees ads – that has a wide set of options (not tried 😉 ).

    Pavan Kumar´s last blog post… Free Website Monitoring Tools to Monitor Website Uptime

  3. This can be done with a plugin called WhyDoWork Adsense.

    It enabled you to even set the number of days the ad should be live, etc.

    Try it as it will be easy for people who don’t want to edit files.

  4. @Pavan, @Prasanth, thanks for the plugin references… I prefer to keep the number of plugins (have just 12 of them) as low as possible and hence edit the code 🙂

  5. Really great tips. Well, i think we can still reduce this code. But this helped me alot.

  6. Thanks a lot, i did many searchs to how to pud ads on each post and i didn’t know where to put the html code in php files, so your post has really helped me! Thanks! <333

  7. Before I start jumping out of excitement, does this work with cache plug-ins like W3 Total Cache?

    I’ve tried so many hacks including Who sees ads but none of them work with cache plug-ins

  8. I just tried the first code on my blog single.php before and it tends to freeze page load. That ‘s the post no longer loads when it gets to the adsense hack. Would you happen to know any reason for this occurring?

    I’d very much appreciate it if you could share a text file containing the code in the first image with us Thanks

  9. I’ve been testing the last code for showing two adsense ads and it has a bug. It tends to create two copies of the same blog post in one page.

    For example at the top of the page is a post without adsense ads and at the end is another copy of that same post, on the same page but with adsense ads showing.

    Can this be fixed?

    • I had tested this successfully on my ‘then’ theme and had absolutely no issues. If you know a little bit of php, you should be able to fix it easily 🙂

      There may be possibly two content filters applied by you somehow.

  10. Hi Ajith,

    great, informative post. I haven’t yet used the code you gave. I was inserting Adsense code manually on some of my WP sites. But I was wondering if there is any easy way to blend the 336*280 block with the post text, meaning the code would be aligned to the left and surrounded with text, just the way you can do with images in WordPress.

    Do you know how to do it?

  11. Thanks a lot. I was looking forward to use ads in the post but this technique is good than using plugins for the same.

  12. I have recently got a website that shows Google ads in the posts. my question is where can i find this code if i wanted to get rid of it and how ??? i thought by disabling the ads in the ads manager would take care of it but it looks as if the code is embedded in the site. any help would be appreciated. thanks.

    P.S. the site in question is

    www. exerciseanddietplans .com

    you will notice that in every post there is a Google ad right before the comments. the 468×60 text and banner ad. please help me figure out, how i can get rid of it.

    • I just checked out that site. You seem to have already disabled ads and comments as well

      • Thank you for taking the time to look in to it. The ads i am referring to are in the post. those are the only ads that are by Google. at the end of every article post you will see and add right under the “Related Post” and right before the comments.


        • Yeah, I see that now. Different themes will have ad codes inserted via different logic/places. Some of the places you have to look into include:

          1) Theme options in your admin panel
          2) Single.php file (BE CAREFUL before editing it if you don’t know anything about wordpress or php. If you are not sure how to edit, please consult somebody who could remove it for you. It’s a matter of seconds for experts)
          3) Sometimes it’s in some other php file than single.php if your theme is based on some theme frameworks.

          I could have done it for you free but we need to establish a connection between our PCs somehow and I am not sure in which timezone are you.
          However, it’s always better to do it with some local help.

  13. It was in the theme options. Thank you for your help..


  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