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.
Instructions
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 :)







October 28th, 2009 at 9:08 pm
Instructions? Just throw into plugins folder and activate? It downloads as a .txt file. Should this be renamed to .php (I assume)?
October 28th, 2009 at 9:27 pm
You is smart :) Added some instructions now.
October 29th, 2009 at 4:18 am
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. http://www.motleyhealth.com/articles/2009/10/live-near-green-spaces-for-improved-health.html
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 Wordpress.org?
October 29th, 2009 at 6:03 am
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!
October 29th, 2009 at 10:16 am
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?
October 29th, 2009 at 12:38 pm
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.
November 18th, 2009 at 8:24 am
I use it on my website and your plugin works like a charm. Thanks and keep it up!
November 18th, 2009 at 5:15 pm
I’m happy it helps you out doing what you do!
November 29th, 2009 at 10:44 pm
This is a very interesting fix for the issue. I’m trying to figure out how to get this working on my blog http://www.insidethewebb.com/ and I think your plugin will work perfectly. Thanks!
December 10th, 2009 at 4:47 pm
[...] 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 [...]