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.