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 :)
15 Replies to “Insert Adsense in Content in WordPress”
Instructions? Just throw into plugins folder and activate? It downloads as a .txt file. Should this be renamed to .php (I assume)?
You is smart :) Added some instructions now.
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?
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!
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?
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.
I use it on my website and your plugin works like a charm. Thanks and keep it up!
I’m happy it helps you out doing what you do!
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!
Thanks! It works great!
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.
Muzzammil
code worked great! You are a genius.