How to put Adsense on your first two posts and sidebar on your Wordpress blog
Google TOS allows a maximum of 3 Adsense ad units on a single page. If you simply paste your ad code into your index.php file of your Wordpress template, Adsense will show up on your first three posts.
You may want two Adsense ads to appear before your first two posts and one in the sidebar as on this site, Rantstoriches.com.
Here’s a simple workaround to accomplish just that:
1. Open index.php in a text editor.
2. Look for the following code:
<?php if (have_posts()) : ?>
3. Immediately before this line, insert the following code:
<?php
$postinc = 1;
$adsense1 = 1;
$adsense2 = 2;
?>
4. Then look for the following in index.php:
<?php the_content(‘<br />Read the rest of this entry »’); ?>
5. Immediately before this line, insert the following:
<?php if ($postinc == $adsense1) {
echo ‘
YOUR ADSENSE CODE HERE
<br>
‘;
} ?>
<?php if ($postinc == $adsense2) {
echo ‘
YOUR ADSENSE CODE HERE
<br>
‘;
} ?>
<?php $postinc++; ?>
6. Finally, open sidebar.php in a text editor and insert your Adsense code in the desired location.
Additionally, you’ll want to repeat Steps 1-5 for archive.php.
That’s it!
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.








This is a very handy tutorial for putting Adsense on Wordpress.