How to show AdSense Ads After First or Every Post in Wordpress Blogs

Posted Posted by hacking tips in Comments 0 comments

This is the most searched and frequently asked question that How can add google ads at home page after posts.
To do this, You need to edit famous wordpress loop. Such a loop can be found in your current wordpress theme’s index.php. There may be other files present in your theme directory which uses loop like archives.php. They may need to be updated as well.
Listed below are steps to edit loop in index.php file. Similar steps can be performed for other files too, if required.
1. Go to Wordpress Dashboard >>Design >> Theme Editor.
2. Click on index.php or Main Index Template file. It will open in Theme Editor on left.
3. Find a line:

4. Add before it:
5. So final code will look:
6. Now find:
7. Add before it:
8. So final code will look:
9. Now inside loop, i.e. after “while” line but before “endwhile” line put your AdSense codes. Exact location depend on your choice between ads before post, ads after post, etc. Important thing is you have to put your AdSense code in a if-block. below is an example…
That’s it. Save changes and check if it works.


1. If you want to put ads after first two post…
In step 9 code, Change $adcount == 1 to $adcount == 2
2. If you want to put ads after first three post…
In step 9 code, Change $adcount == 1 to $adcount == 3
3. If you want to put ads after each post…
In step 9 code, Change $adcount == 1 to $adcount == 3. Yes this is same like above. Because AdSense only allows maximum three ad-units on a a single page. This way you avoid blank space created after each post when you directly put AdSense code after each post.


Post a Comment