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.

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/svarogg/public_html/wp-content/plugins/runPHP/runPHP.php(383) : eval()’d code on line 3

Warning: include(http://cashcook.info/adsenseskyscraper.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/svarogg/public_html/wp-content/plugins/runPHP/runPHP.php(383) : eval()’d code on line 3

Warning: include() [function.include]: Failed opening ‘http://cashcook.info/adsenseskyscraper.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/svarogg/public_html/wp-content/plugins/runPHP/runPHP.php(383) : eval()’d code on line 3

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 <body> tag:
<?php $GLOBALS["x"]=1; ?>

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:
<?php
if($GLOBALS["x"]==1){
include “adsense.php”;
$GLOBALS["x"] = 2;
}
?>

If you display two ads per page, use this code:
<?php
if($GLOBALS["x"]==1){
include “adsense.php”;
$GLOBALS["x"] = 2;
}
else if($GLOBALS["x"]==2){
include “adsense.php”;
$GLOBALS["x"] = 3;
}
?>

If you display three ads per page, use this code:
<?php
if($GLOBALS["x"]==1){
include “adsense.php”;
$GLOBALS["x"] = 2;
}
else if($GLOBALS["x"]==2){
include “adsense.php”;
$GLOBALS["x"] = 3;
}
else if($GLOBALS["x"]==3){
include “adsense.php”;
$GLOBALS["x"] = 4;
}
?>
I suggest you write down the appropriate code in a text file, so you can quickly cut and paste it into your code.

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/svarogg/public_html/wp-content/plugins/runPHP/runPHP.php(383) : eval()’d code on line 7

Warning: include(http://cashcook.info/adsenseskyscraper.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/svarogg/public_html/wp-content/plugins/runPHP/runPHP.php(383) : eval()’d code on line 7

Warning: include() [function.include]: Failed opening ‘http://cashcook.info/adsenseskyscraper.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/svarogg/public_html/wp-content/plugins/runPHP/runPHP.php(383) : eval()’d code on line 7

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

If you enjoyed this post, buy me a beer.

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Related Reading:



Thank you for reading this post. You can now Read Comments (5) or Leave A Trackback.

RSS feed | Trackback URI

5 Comments »

Comment by ter
2007-06-14 07:13:55

thx 4 very usefullll post !

cool blog !

 
Comment by alex Subscribed to comments via email
2007-07-08 23:35:25

i like this post, but i can understand your code because some characters display wrong, i see this:

what means ”x”] ?

Comment by Svarog
2007-07-09 05:41:36

Thanks for the comment alex!

Something really weird happened to this post, and some of the characters got distorted.
I can only guess what is the cause of this distortion.

Anyway, now things are, hopefully, fixed, and the code is correct.

 
 
Comment by unidcatn
2008-03-04 18:40:49

kuywcgay http://oawjguml.com fiaskqmh qxemrqgd

 
Comment by Netmark
2008-03-31 01:20:35

The wordpress adsense plug in allows only three ads per post or page. I did not find any problems with more than three ads units. Please note: each ads units could contains more ads, up to four!

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image