How to Add Ads Between Posts on Home Page (WordPress Blogs Only)
Please Subscribe to our YouTube Channel
Adding ads on Home Page could be difficult if you are using such WordPress Themes that don’t have any option to add ad tags on Home Page. However, it’s not as difficult as it may seem and you can do it without using any WordPress Plugin. You need to add/modify the code that we will talk about. Before you do that, please take a backup.
How to add Adsense or other ad banners on the Home Page of your WordPress Blog or Website?
- Go to the WordPress Blog’s Admin Panel.
- Hover Mouse Pointer on Appearance, and click on Editor option.
- Now click on Index.php and looks for these codes;
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
- These codes may or may not be together. In my case, they are not together as you can see in the screenshot below.
- Now delete both of the code lines we mentioned above and type the following code;
<?php $postcounter = 1;
if (have_posts()) : ?>
<?php while (have_posts()) : $postcounter = $postcounter + 1;
the_post(); ?>
<?php if(4 == $postcounter)
{ echo ' <div id="adsbetween">
<center><Your Adsense or any other Ad Tag></center>
</div> ' ;
} ?>
- The ad with the code above will appear after 2 posts on the Home Page, If you want to make it appear after the first post, you can replace 4 in with 3. For example, <?php if(3 ==$postcounter)
- Now there are many bloggers who want to serve multiple ads. In that case, you can add another code right after the code we mentioned above, and then you can keep adding as many times as you want. Type the following code for another ad banner right after above-mentioned ad code;
<?php if(6 == $postcounter)
{ echo ' <div id="adsbetween">
<center><Your Adsense or any other Ad Tag></center>
</div> ' ;
} ?>
- Now you can keep replacing the number and add mode ad tags to show at different positions. If you want to give some space after ad (before the post), just type <br> in the end of the ad tag. There is no need to type any closing tag for <br>
Here is how it looks like in Index.php after you add ad tags.