Monday, 9 July 2007

Integrating Adsense in The Body Of Your Post

Integrating Adsense in The Body Of Your Post

When blogging, one of the best spots to place your Adsense Ad is in the body of your post.
CashCook.Info receives 75%+ of it’s clicks from the ads that I integrate in the post.

There’s only one problem with those ads. Google Adsense allows no more then 3 Ads on a single page, and with the standard tools Wordpress supplies, on all pages that have more then one post(front page, search results, archives, etc.), all posts that contain Adsense ads will display those ads. Needless to say, eventually you will get banned.

After searching around the internet, I haven’t found any plugin that deals with the problem, and decided to create a solution myself.

I can say for sure that this solution is not the most elegant solution there is, and maybe creating a plugin would have been the best idea, but I’m the lazy type of a person, never coded a plugin before, and for now did not know all the syntax one needs to learn so that he can write Wordpress plugins.

Enough ranting, let’s see how is it done:
First of all, you’ll need some plugin that will enable you to run PHP code within posts.
I personally use runPHP. It’s very easy to install and use, only annoying part about it, is that you have to tick the option to run PHP code each and every time you write a new post, and I tend to forget that.

Next, create a file in your blog’s home directory called adsense.php, which will include your Google Adsense code.
Now, go to your theme editor, and add the next line in your header, anywhere after the tag:

That’s it, you are done with preparations, and are ready to insert Adsense code within your posts.

Now wherever you want to ad Adsense in your post, ad one of the next codes, according to the number of such ads you want to display per page.

If you display one ad per page, use this code:

If you display two ads per page, use this code:

If you display three ads per page, use this code:

I suggest you write down the appropriate code in a text file, so you can quickly cut and paste it into your code.

P.S.
Just don’t forget to tick “run PHP code?” each time you write a new post.

No comments: