For those of us who write paid posts, it has been very hard to insert adsense blocks within your posts in a global manner, as the Terms Of Service of PayPerPost and other paid blogging services prohibits this.
Thanks to one of the simplest, yet most useful tips that I ‘ve ever come across, RT at Untwisted Vortex has the answer to this problem: Don’t display Google Adsense within sponsored posts on your WordPress blog.
If you’ve been looking for something like this, go visit RT and grab the code. All you have to do then is insert it into your theme pages in whichever manner suits. RT has chosen to incorporate adsense into his blog homepage (you’ll need to edit index.php) and a single post page, whereas for now I’m only using it on the single post (edit single.php)
As he explains, the code simply searches the post contents for the words “This is a sponsored post” and if it finds them, it will not display adsense, as per the TOS. Otherwise, adsense will appear in every post. (You may be wondering how adsense has appeared on this post – it’s because I left the period off the end of the trigger text in this example-my real paid posts will include them).
You can of course amend this trigger text to anything you want, and it could also be used to prevent ads appearing on other types of post if you so choose-just make sure the text you choose isn’t common enough to appear in a normal post.
You will need to experiment with the placing of the code within your PHP files to suit yourself – I entered mine directly after the ‘div class=”entrytext’ line, but it may differ for your particular theme. Just remember to take a spare copy of the file before you begin editing it!
This is so simple, yet effective it deserves a virtual round of applause. Turn this into a plugin RT, and you could be onto a winner.





13 users commented in " Selectively Display Adsense Within Your Posts "
Follow-up comment rss or Leave a TrackbackInteresting but there’s better ways of doing this. I use a custom field for this sort of thing – maybe I should write about it in one of my tips and tricks articles
Also I don’t remove ads on review posts, but then I only use reviewme and they have never complained about ads.
I’d be interested to read that Ben – PPP and some of the other companies would reject any posts with ads in them, so it was just what I was looking for.
So do they not allow you to have ads on the archive pages as well? I would have thought it would just be the page with the review, not the pages listing the reviews.
Also would they allow you to add adverts after, say, a month?
As I understand it, you cannot have the ads within the body of the post, which is apparently the best spot for adsense.
After 30 days you can effectively delete the sponsored posts, so yes you can add them then.
Ok – that’s interesting to know. So how about something which let’s you display adverts once a post is a certain age.
That’s exactly what I do on my own site all the time, recent posts have no/ one ad and older posts have more
Do tell
[...] Selectively Display Adsense Within Your PostsWho Would Like $800?Save Money With Coupons [P]Hosting TroublesFree PR7 Links From Binary Moon [...]
Experiment, experiment, experiment! This is what it takes to succeed with AdSense. Or at least in my past experience…
What about for blogspot?
This method wouldn’t work Claire, but I’m sure someone would know a way. Think you’re stuck with doing it by hand for now…
Chris – I have added this to my todo list and will write a post on the subject in the next week or so
Great, will look forward to it
[...] this is the plugin Chris from Blog-Op wanted when he wrote "Turn this into a plugin RT, and you could be onto a winner.". I'm considering whether to hack the exclusion function to be specific to the "This [...]
Leave A Reply