How To Insert Google Adsense Units Between Posts In Index Page

This article will show how you can easily insert, not only, Google Adsense ad units between posts in index pages. In most cases, website owners and bloggers using WordPress as a CMS gets their own free or premium WordPress templates or themes from various sources. Like the one I am using, it is a premium WordPress theme from Theme Junkie. Sometimes there are themes that provide an option where you can put your Google Adsense unit codes and it automatically post your ads between the posts from the index page. But what if the WordPress theme you are currently using does not have that option? Can it be done manually? The answer is yes!

How To Insert Google Adsense Units Between Posts In Index Page

I guess there are WordPress plugins that are readily available to do the trick but as much as possible I don’t want to depend so much with these cool tools or addons just to do the specific tasks I wanted. One main reason is that it adds up to the total speed and performance of a website. So here’s a quick and easy way to manually code the Google Adsense ad units so that they will appear between the posts in your index page (front page).

A must read:   Website Loading Speed – Quick & Easy Steps To Increase The Speed

Before everything else, it will be wise if you can backup first the file that we will be altering here so that you can easily revert to the original if something goes bad. But if you will follow the instructions here carefully then there’s nothing to be worry about since I have personally tested them.

The file that we will be altering here is the index.php. You can edit it either from cpanel, straight from your WordPress dashboard (that is if you have the admin level account), or you can download it locally and upload it back once you are done. Again, I encourage you to backup your files first.

Now that you know which file you have to edit, the next thing to find is where the looping of each posts start.  Look for this line from your index.php:

Then put the following above it.

And below the first code above, place these lines.

You can adjust the $count values from the code above depending on how you want to present your ads from your index page. What the code simply does is that it puts the ad units on the top of the first post from the loop and the other one on the next.  I have added a div parameter to put a little bit margin around your Google Adsense code.

The end result? Look at the image below. This is the what I have implemented on my other tech blog site.

Google Ads posted in between


Hi, I am Arsie "RC" and I am a freelancer tech blogger. Most of my articles and posts are tech-related stories and most of it covers the latest Android or Apple apps, gadget reviews, Microsoft updates social media updates, tips and tricks, SEO and making money online. If you wish to contact me, go ahead and visit our contact page. You can follow my updates on Twitter, Facebook, or on Google+ profile. You can also check my other tech blog site for more informative news.

No comments.

Leave a Reply

CommentLuv badge