Written on March 9th, 2006 at 11:03 pm by Aaron Brazell
How to: Placing Adsense Strategically Between Posts
Greetings, fellow Probloggers (and those who aspire to be probloggers). It’s somewhat surreal to be posting here. Darren’s highlighted who I am pretty well (though I’m not sure where he dug up that photo!), so I’ll simply add that my strength lies in WordPress. I have been an active part of the WordPress development community for some time, so it will be natural to pass along some things I know from my experience with the platform. Some of the tips I write about will be very easy for some, and hopefully there will be entries that challenge even the most advanced. As long as someone is learning, I’m happy.
A few days ago, Darren posted an entry about ad placement that took an interesting turn in the commentary that followed.
Commenter Tom asked:
What is the plug in that you use to put the ads between the 2nd and 3rd post, or do you do so manually?
That, my friends, is the tip of the day. WordPress is a very flexible platform that allows for quite a bit of “munging” to make things work right. For starters, the basic building block of WordPress is a block of code called “The Loop”. It is called that because, literally, it is where the posts for a given page are “looped” through repeatedly to be displayed on the blog.
The standard Loop in the index.php file, is a block of code that might look a bit like this:
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;
A basic explanation of this block of code is:
- If there are posts to display on a page, then
- We begin processing the posts one by one as long as there are posts to display
This is, in fact, the absolute minimum that a Loop requires and it will get the job done. The blog won’t be much to look at, but it will display entries successfully. But how do we know where to put the Adsense code?
Here’s the trick: We can actually count how many times Loop has cycled and use that information to our benefit. That same block of code with a counter might look something like this:
// Set Counter to 1, First Post
$counter = 1;
if (have_posts()) :
while (have_posts()) :
$counter = $counter + 1;
the_post();
the_content();
endwhile;
endif;
Here we’ve dropped a variable, $counter, into the code, set its initial value to 1 and simply incremented it by 1 after every pass through the Loop.
Now we can worry about determining where to put the Adsense code.
// Set Counter to 1, First Post
$counter = 1;
if (have_posts()) :
while (have_posts()) :
$counter = $counter + 1;
the_post();
the_content();
if(2 == $counter)
{
echo ‘Adsense code’;
}
endwhile;
endif;
Bam Bam Bigelow. That’s all there is to it. Drop your own Adsense code in there and you’re off to the races. Just as a precautionary note, make sure you place the if conditional and Adsense code before the end of the Loop. Most forms of the Loop end before endwhile, but there is a chance that your Loop doesn’t use this same format.
I hope this helps. Feel free to drop requests here in the comments. I’d love to tackle the issues that you as bloggers face and see if we can’t discover more ways to make our blogs sing.



68 Responses to “How to: Placing Adsense Strategically Between Posts”
Josue
March 10th, 2006 12:26 am
Thanks so much! Man, you put Wordpress and people like you guys together and this is like heaven! =)
The Wordpress community is awesome.
Tom
March 10th, 2006 12:30 am
Great tip! You wouldn’t happen to have a similar tip for the Blogger tool, would you? Most of the Blogger scripts are simple javascript. Would changing the index page type to PHP allow this to run (assuming the hosting service supports PHP)? Wouldn’t you then have to change all of your pages to php as well, like the auto-generated archive pages? Thanks in advance.
Btw - enjoyed your podcast interview a few weeks ago (think it was with Yaro…)
Tom
racketboy
March 10th, 2006 12:36 am
I’d love to see Blogger ones too.
Wezzo
March 10th, 2006 12:43 am
Yeah great stuff, as racketboy says love to see Blogger ones
Aaron Brazell
March 10th, 2006 12:53 am
The Loop is only WordPress though other systems have similar concepts. The thing to realize, The Loop (or similar thing) is executes on the server prior to any information being sent to the browser. In the case of Blogger, unless you have access to Google’s servers, you’re not likely to have the same results.
If people are interested in seriously leveraging their blog, I usually recommend a move to a self hosted solution such as WordPress. Or even Moveable Type if you can figure out how to get it working. ;)
Elliott Back
March 10th, 2006 1:08 am
I usually write something like
to get read of the increment line. You can also put your ads every 2nd, 3rd, 4th, etc post with a finite field:
Aaron Brazell
March 10th, 2006 1:09 am
Elliott, me too. Just starting out with code that might be a tad easier to understand. :)
markus
March 10th, 2006 1:26 am
You start with counter=1 and then you use counter=0. It’s a small mistake.
I also use some kind of code like this. Works fine.
Aaron Brazell
March 10th, 2006 1:29 am
Well met, Markus. Fixed that error. :)
Eric Gregory
March 10th, 2006 2:00 am
I’ve been waiting for someone to write about this. Awesome!
Now if only someone would show me how to do this in Drupal…
Jon Heizer
March 10th, 2006 2:25 am
Nice post and welcome to ProBlogger! Being a programmer, I will look forward to your posts.
Jhon Hopkins
March 10th, 2006 3:35 am
Thanks for the tip, it really works for me and my blog
Jake
March 10th, 2006 3:38 am
Hey great post Aaron!
You made this simple. So many others hae tried to help people with this yet you put it in easy steps.
I am sure thousands are very happy right now and you made their day.
If you get a chance can you head to:
Raise Your CTR by 200% and tell me what you think.
Thanks.
Joshua K
March 10th, 2006 4:15 am
Oh yeah, that’s some goodness. Thanks for this tip! (Elliott, good coding tip there too.. I’ll be using that a lot in the future).
Quick Online Tips
March 10th, 2006 5:04 am
Some tips for placing adsense inside Blogger posts.
coglethorpe
March 10th, 2006 5:33 am
This is the stuff! I’m about to update my theme to include this. The new layout may well work better than the left hand skyscraper I use now.
Michael Hampton
March 10th, 2006 6:31 am
I used to use an old plugin called Moose Candy to insert content between posts. It would let you insert whatever you wanted in between specific posts. So you could have an AdSense ad between the second and third posts, a quote of the day at the top, or just about anything you can imagine. Unfortunately, the person who wrote the plugin has gone away, and it’s no longer available as far as I know.
Aaron Brazell
March 10th, 2006 7:30 am
I’m glad this topic is being so well recieved. Makes me excited for the future. Something I’m thinking about doing is a mini-series on creating a plugin but I’d like to do one that the community can benefit from when the series is all done and the plugin is available. So folks, feel free to pitch a plugin to me and let’s see where the dust settles? :)
Aaron Brazell
March 10th, 2006 7:36 am
Michael— you’re on the WP Testers mailing list, no?
Tom
March 10th, 2006 7:51 am
Thanks!
Ask a question, get an answer.
That is why we love Darren and all his friends.
Tom
Eric Giguere
March 10th, 2006 8:45 am
I don’t use WordPress (I use blojsom) but I did a similar thing with my blog, and just wanted to add something: don’t forget to use the alternate URL feature to display other ads if AdSense can’t find an ad to display. You can easily create your own Google-like ads to promote products sold via affiliate links (like from ClickBanks or Amazon) so that you never have any empty space where the ads would be…. see the cheezy “Ads by Eric” on my blog, for example (scroll past the first three, those are real AdSense ads).
Martin
March 10th, 2006 10:22 am
very old trick :))
Aaron Brazell
March 10th, 2006 10:25 am
Indeed! But apparently one that many readers did not know. :)
Bill Hutchison - Help me Pick A Name
March 10th, 2006 12:18 pm
Thank you, I have been wondering how to do this for ages. Even though some say it is a “very old trick” I had not found how to do it.
Probably using the wrong search terms…
Tom R.
March 10th, 2006 12:58 pm
I managed doing the same though using a different method. Yes, it’s possible to do something similar using other way. But mine is, I would say, easier to manage. I got the wonderful http://www.acmetech.com/blog/adsense-deluxe/ plugin which allows me to plug the ad into the script easily.
My code is only added at 3 different places in the templates files:
1. In the theloop.php, find
–>
then add
This code will output a ad every 3 posts (but beware, google TOS says no more than 3 ads per page, so I’ve warned you).
2. In the sidebar.php
just before the div class clear, add
This code output the ad in the sidebar
3. In single post
add
after the call.
This will output the ad just before the comments and the comment box.
Using ad sense deluxe (which you should have actived), create a block called MidPage (which would generally contain the code for a 468×60 banner) and a Sidebar (which contains any scrapper kind) and you’re done. Might be a bit long, but it’s easier to manage after.
Add adsense in your Wordpress blog at Ma chienne de vie (excitris.com)
March 10th, 2006 1:05 pm
[…] After writing a comment on http://www.problogger.net/archives/2006/03/09/how-to-placing-adsense-strategically-between-posts/, I was “due” to post it here. […]
Tom R.
March 10th, 2006 1:06 pm
Since it seems I can’t get my code to show properly, I might suggest you go check the “same” text on my blog post (done for the purpose)
http://excitris.com/2006/03/09/add-adsense-in-your-wordpress-blog/
marcel
March 10th, 2006 3:45 pm
you can do the same with Drupal… after you hack the code
Nathan Weinberg
March 10th, 2006 4:40 pm
Yeah, the Moosecandy plugin does a great job letting you insert AdSense (or anything) after any specific post. You install the plugin, and then all you have to do is edit a text file, specifying:
The number of the post
The code you want to insert
You can put in anything, from ads to plain old text, and it involves very little actual thinking. A simple Google search will find the plugin, although some download sites no longer work.
arZan
March 10th, 2006 5:03 pm
Any help on this for Movable Type.
Will be greatly appreciated.
Prince
March 10th, 2006 5:51 pm
Hey Aaron,
Will you tell me
How to wrap the adsense ad with Post Text in blogger blogs?
Thanks, bye
Prince John
Josue
March 10th, 2006 6:33 pm
There is also this page that explain it very well with different options:
http://www.tamba2.org.uk/wordpress/adsense/
Oyvind
March 10th, 2006 8:31 pm
What if you want to use some php code instead of pasting the adsense code directly?
If you use the adsense deluxe plugin (http://www.acmetech.com/blog/2005/07/26/adsense-deluxe-wordpress-plugin/), you place the ads with code.
From the help page:
—
Name
This is the name by which you reference an AdSense block of code when creating posts. For example, if you name a block “wide_banner”, you would insert into your post
“”.
—
But if I substitude
echo ‘Adsense code’;
with
echo ‘’;
I get an error?
Adsense Tips: How to place your ad between your blog posts in Wordpress « Sabahan.com
March 11th, 2006 3:37 am
[…] To change the frequency of the Adsense ads, just change the number ‘3′ above to a different number. If you want to display one ad only after the 2nd , 3rd , 4th etc and not have it repeated, you can refer to the original tips at ProBlogger on how to do this. […]
Thilak
March 12th, 2006 2:04 pm
i wanted to put adsense link unit below every post so i put my adsense code in the loop. but it displays ad only on first 3 posts . plz help me darren
JonP
March 14th, 2006 9:08 am
And remember to turn off Adblock from Firefox! Confuses things for simple people.
Thanks, Jon.
Greg
March 15th, 2006 1:46 am
Thanks! One quick question.
I’m using a 3-column theme ( WordPress blog developed using Semiologic CMS, original theme design by Mesoconcepts, modified). The call for the posts (if statement) isn’t located in the index.php file. What file, other than the index.php file, might it be in?
I understand how to edit the loop, just can’t find it.
Learning something new about WP everyday. Any assistance you may provide is appreciated.
Greg
March 15th, 2006 1:48 am
Oops! Mis-typed my website address in the previous post. This post has my correct address (www.eoecho.com/allthingsmercedes/).
otro blog más » Unos cuantos de desarrollo web (LXXXI)
March 18th, 2006 10:30 pm
[…] Placing Adsense Strategically Between Posts explica precísamente eso: cómo colocar la publicidad de AdSense (o cualquier publicidad, o cualquier otro contenido) entre las entradas de WordPress, modificando su bucle. […]
John
March 28th, 2006 6:21 am
That’s a great tip and I thought the pro wrestling reference was way cool! (Bonus points if anyone else can figure it out - the points don’t matter, but it’s nice to know they’re there)
John
Adsense Money Websites
March 28th, 2006 3:46 pm
Blogger: Followed the instructions from comment 15 and worked like a treat. Thanks
WordPress Hispano » Blog Archive » Mostrar anuncios entre entradas
April 2nd, 2006 6:12 pm
[…] [VÃa] […]
QiSoftware
April 24th, 2006 12:40 am
I wrote a similar function in JavaScript — Ads Under First Post. Awhile back, Google claimed my code was not what they provided and because of this could not anaylze why I had problems with impression counts. Your echo above — would be equavilent to the changes I made.
I must admit, Google — in later communiqués, did not reiterate their issues with the JavaScript function.
A warning for those considering some sort of code trick to insert AdSense ads in posts.
Netwalker
April 26th, 2006 1:20 pm
I implemented this in my blog.
I have one link unit at the top of the page, one ad unit on the sidebar of my blog and the adsense for search.
But after doing the changes explained here, it only appears the one that goes between the post 2 and 3, but the one in the sidebar it’s not showing any more.
Does this means that I have more than the allowed ones? as I understand I can put 1 link unit, 1 adsense for search and 3 ad units in the same page. So I’m not going over the allowed quantity. Or it means it doesn’t has ads that match my blog?
Thanks in advance.
jai
April 26th, 2006 7:04 pm
I implemented this in my blog.
I have one link unit at the top of the page, one ad unit on the sidebar of my blog and the adsense for search.
Download Toolbar RSS (Free) & with advanced features. You can send messages to all users.
Giorgi
May 3rd, 2006 6:29 am
Hello, Gr8 ppl!
I have question, in my index.php there is:
“>
so, can anybody modify it so I can diplay ad after every 5th post?
Thank you in advance
thedude
May 6th, 2006 3:03 am
Hello Everyone,
I am using a wordpress theme, but my code looks like this…
How would I modify it to show my google ads between posts? Additionally, if I use this method, will my google ads between posts be shown in my permalinks and/or categories?
I am very new to the blogging world and am just in the process of setting up my blog the way I want it. Please help me if you can. Any advice would be very appreciated.
thedude
May 6th, 2006 3:04 am
It did not show my code on here! I don’t know what is happening!
Here is my code again I have removed the “” from it.
?php if (have_posts()) : ?
?php while (have_posts()) : the_post(); ?
?php require(’post.php’); ?
?php endwhile; ?
Aaron Brazell
May 6th, 2006 4:08 am
thedude… WordPress strips code so you have to fudge it.
In answer to your question, it doesn’t really look like you did what I suggested above. If you go back and read the entry and follow along, you’ll get your ads between posts. Luck to you!
gaby de wilde
May 8th, 2006 6:32 am
If you want adds with all your posts on the blogger blogspot blog you can put the code inside the <Blogger> tags and set the maximum number of posts to 3. You would have to make sure they don’t show up on the archives by using <MainPage> tags around them.
But if you want more as 3 (or more freedom over placement) you put the ad code inside the <BlogItemCommentsEnabled> tags then disable the comments for all but 3 posts.
Do adjust the blog settings to “new posts have NO comments” or you will end up with more as 3 adverts per page(more as allowed)
http://categories.blogspot.com/2006/04/adsense-between-posts.html
Adsense between posts
Blogging Resources»Blog Archive » How to: Placing Adsense Strategically Between Posts
May 11th, 2006 5:37 am
[…] How to: Placing Adsense Strategically Between Posts […]
Implementing Ads in Between Posts--SEOnoob
May 16th, 2006 3:15 am
[…] How to: Placing Adsense Strategically Between Posts Adsense Tips: How to place your ad between your blog posts in Wordpress […]
Asha
June 5th, 2006 2:12 am
I’ve just written up a tutorial on how to place Adsense between posts in TypePad.
importers-exporters
June 17th, 2006 11:05 pm
If you can’t use an imagemap, or if you’d rather access the editorials through a more conventional table of contents, all 28 are also arranged by newspaper and date. Clicking on the paper at left will take you to that list. stylishcn com Clicking on the paper at left will take you to that list importers-exporters http://www.importers-exporters.com/jewelry_watches.htm
An experiment in futility :: links for 2006-06-28
June 29th, 2006 4:27 am
[…] How to: Placing Adsense Strategically Between Posts (tags: wordpress adsense) […]
Best Numbers
July 10th, 2006 2:27 am
I want to say big thanks to:
” http://weblog.ashaland.com/ashaland/2006/06/how_to_place_go.html ”
for great ’step by step’ tutorial that helps me a lot.
All in a days work… » Blog Archive » links for 2006-07-24
July 24th, 2006 10:37 am
[…] Placing Adsense Strategically Between Posts read the comments (tags: AdSense Blog_Tools) […]
Oscar
August 11th, 2006 9:32 am
Can anyone here help me figure out a way to only have ONE or TWO ads appearing in my main column after the first two pots?
My problem is that all THREE of my ads are appearing in the main column after posts, and an addition MIDDLE column I maid specifically for ads is EMPTY because the main column is using up all the ads I am allowed.
Can anyone help me find a way to limit how many ads are after my posts to lets say one or two?
Thank you very, very much. I really do appreciate it!
malique
January 7th, 2007 10:19 am
i tried this on wp 2.0X and it didnt work.
another blog of mine which is still 1.5 (haha, yes i know) worked well.
would appreciate it if there is a revised tutorial for 2.0x and above.
Cheers!
Websites Made Simple Blog » Blog Archive » How To: Insert Horizontal Banner between 1st and 2nd Post - Sharing simple website design, ideas, practices with Malaysia.
January 15th, 2007 11:52 pm
[…] In early 2006, Darren of Problogger initially released a tutorial for this but at the last comment someone said that it wasn’t supported on version 2.x and only version 1.5. […]
Danny Foo
January 16th, 2007 12:08 am
I stumbled on a different method that works on version 2.x
Just posted the tutorial over at my place with reference to the original source. I explained the process in layman so it’s easier to understand. :)
http://www.dannyfoo.com/blog/2007/01/how-to-insert-horizontal-banner-between-1st-and-2nd-post/
Cheers.
Brandon Hopkins
February 23rd, 2007 8:58 am
I’m trying to get it to work, and it’s kinda showing weird things instead of adsense…see after the first post:
http://www.freebusinesscards.info
NGeN
June 9th, 2007 7:16 am
hi..
while this tweak worked on a normal theme i had before.
the current theme im working on had tags closed at every line
Which will lead to printing out of these code when one pastes these.
Then i figured that the addition will make them work..
so if the code is being printed out for all of you instead the ads being displayed in the desired postion
try the tags…
ie, paste these in the positions Darren has mentioned
Hope this wil help someone if they experience a problem similar to mine. and thus saving precious time for producing contents…
and also thanks to Aaron , and also Great blog Darren :D !!
NGeN
June 9th, 2007 7:23 am
Ohh the code got stripped
here it is .. :)
remove spaces between ? and > or
Rukshan Kothwala
July 10th, 2007 2:18 am
Thank you very much!.I have a method to do it on Blogger blog.
http://www.thesitewriter.com/2007/07/how-to-place-adsense-ad-unit-between.html
Alex
December 27th, 2007 2:52 am
Thank you!!
I’ll try this on my blog… :-)
Mike
January 26th, 2008 10:53 am
I know this is a old post, but I keep finding it for help with this problem. But it did not work for me because of WP 2.0, here is the link that worked for me
http://www.lancelhoff.com/2007/02/28/adding-adsense-ads-between-posts/
Ad Between Posts: Wordpress | Le Pixel Shoppe
May 5th, 2008 3:33 pm
[…] can also check out this site and this site for other ways of adind code betweeb blog […]
Leave a Reply