How to Add Ads After the First Post in WordPress

If you would like to place an ad; i.e; Adsense ads or anything else underneath just the first post on your WordPress blog and don’t want to use a plugin, you can use the following code.

First, open your Main Index Template (index.php) or if your theme uses Loop template files, open loop.php, and find the following line:

?Download download.txt
1
<!--?php endwhile; ?-->

Or this line of code if you’re using the WordPress default theme, “Twenty Ten”

?Download download.txt
1
<!--?php endwhile; // End the loop. Whew. ?-->

Add the following line before the code above, adjusting it as you see fit. (I’ve added div tags to center my ad)

?Download download.txt
1
2
3
<!--?php if(!$show_ad){ ?-->
<div style="text-align: center;">YOUR AD CODE GOES HERE</div>
<!--?php $show_ad = 1; } ?-->
Share