The Person

Hard-core family man. Loyalty. Strength. Dedication to one another.

A love of words, writing, reading, listening, singing, praising, rejoicing.

Comfort the frightened, help the weak, be patient with everyone.

The Professional

Self-employed web publisher. Programmer. Developer.

Consultant. Aid. Help. Advisor.

Happily employed with Search Engine People.

Insert Adsense in Content in WordPress

While ago I was playing around with inserting Adsense ads not somewhere floating before or after the content but in it.

I hacked programmed some code together which inserts Adsense after the xth paragraph.

Someone asked for something just like this so I thought I would throw this out there.

When I used it I used it as a function in functions.php; I prefer to keep most of my stuff there vs. running plugins. I’m releasing the code in plugin form though.

Usual applies: no warranties, no promises, if it’s broke it’s your problem, yadah yadah.


Download the file below by right-clicking on the link and Save As…

Open the file and insert your Adsense code in the $adsense variable.

Rename the file from .txt to .php, upload to your plugin folder and activate.

Alternatively you can add the add_filter and function to the functions file in your template folder. If that makes no sense or raises more questions, you’re better off with the plugin option :)


Right-click here & Save As

15 Responses to “Insert Adsense in Content in WordPress”

  1. DazzlinDonna Says:

    Instructions? Just throw into plugins folder and activate? It downloads as a .txt file. Should this be renamed to .php (I assume)?

  2. Ruud Says:

    You is smart :) Added some instructions now.

  3. Jon Says:

    Excellent plugin Ruud. I am having a few minor problems, but that is probably down to oddities in WP. I have set it to 2 para but sometimes it seems to come after 3, and in one case it comes straight after an image, e.g.

    But not bothered, as that may be a good place for it anyway!

    It got me thinking – how many other useful plugins are out there which never make it onto

  4. Ruud Says:

    It uses the times you pressed [enter] as a way to split the post up. Those markers aren’t always accurate. I could expand the regex a bit but this did the trick for me.

    Glad you like it!

  5. Jon Says:

    Seeing that you have done this already, and I am still experimenting on ad format, have you found any particular shape/colour/position to work best?

  6. Ruud Says:

    It depends on your page. Good way is to prepare a page load. Hit [enter] and look away from the screen. Look up at it (or open your eyes) and see which spot you see right away: that’s the immediate scan zone where you should place your ad.

  7. bruneifm Says:

    I use it on my website and your plugin works like a charm. Thanks and keep it up!

  8. Ruud Says:

    I’m happy it helps you out doing what you do!

  9. Destiny Islands Says:

    This is a very interesting fix for the issue. I’m trying to figure out how to get this working on my blog and I think your plugin will work perfectly. Thanks!

  10. Top 20 Favorite Twits: December 2009 | Linda Carmical Says:

    […] geek. He has some really good posts on his blog, RuudHein; I’m particularly fond of “Insert Adsense in Content in WordPress“. I’ve just got one problem with it Ruud, I’m not very bright and have no idea […]

  11. Adsense code within content and after defined paragraphs Says:

    […] Ruud Hein has written a nice little hack that will insert code after the n’th paragraph. It comes as a plugin so you won’t have to update code as you upgrade WordPress. […]

  12. Thomas Says:

    Thanks! It works great!

  13. Muzzammil Says:

    It works like a charm Ruud… I’m using it on my site.

    How about modifying it to insert an ad multiple times in case the post or article is a lenghtly one, let’s say 6+ paragraphs?

    furthermore, any guidelines on inserting text ads of link ads and what sort of formatting yields better results..

    Much appreciated.


  14. Tom Says:

    code worked great! You are a genius.

  15. AdSense Code in your Wordpress Specified by Paragraph | Googlenetics Says:

    […] Ruud Hein has written a nice little hack that will insert code after the n’th paragraph. It comes as a plugin so you won’t have to update code as you upgrade WordPress. […]

Leave a Reply

Subscribe to Comments?

Recent Readers.Recent Readers