Insert Adsense in Content in WordPress

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

Download

Right-click here & Save As

15 Replies to “Insert Adsense in Content in WordPress”

  1. 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?

  2. 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!

  3. 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.

  4. 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

Leave a Reply

Your email address will not be published.