Better AdSense Optimization with WordPress
Looking through Google AdSense advice and suggested places to put your advertisements, I often see it suggested to put the ads between your posts on the index page. Having searched around for ways to get it done, I found none that were easy – until I found this page.
This is the guide I followed from tamba2.org.uk’s page on this issue. I hope this comes in as handy for you as it did for me, because it took me forever to find a code combination that worked exactly like I wanted it to.
Copying from above, you would use this instead:
<?php
$postnum = 1;
$showadsense1 = 1;
$showadsense2 = 2;
?>
which would go at the top.
Again copying from the above, you already have this:
<?php if ($postnum == $showadsense1) {
echo ‘
Your adsense code goes here
‘;
} ?>
<?php $postnum++; ?>
and you would add another block below the first ad, but above the counter at the bottom. Here it is all together:
<?php if ($postnum == $showadsense1) {
echo ‘
Your adsense code goes here
‘;
} ?>
<?php if ($postnum == $showadsense2) {
echo ‘
Your adsense code goes here
‘;
} ?>
<?php $postnum++; ?>
The first bit says the values, then the values are checked each time WP goes through The Loop. If the counter matches what your value is, the ad is shown. Changing the numbers lets you change the placement.
Hope that helps, and many thanks to the tamba2.org.uk site. Be sure to check out this page for more help on AdSense optimization within WordPress.


September 23rd, 2009 at 9:33 am
For those of us who would rather use a plugin than edit files… the plugin “Advertising Mgr” works well for me. You can find it here: http://code.openx.org/projects/show/advertising-manager
(no, I’m not part of the project)