BlogKnowHow apologies for the technical problems with the site. We are working on it and hope to resolve the issue as soon as possible.

Wednesday, June 17, 2009

Add Banner Adsense Above Blogger Header

One of my readers asked me how to add a Google Adsense ad unit above the header of a Blogger Blogspot blog. Rather than post a long reply I decided to write an article about it so that others looking for help to place an affiliate banner or Google Adsense banner at the top of their blog will find the solution more easily.

To set up Blogger so that ad units can be placed above the header requires the addition of a snippet of code to your Blogger Template. I have aimed this tutorial at beginners and newbies to Blogger. The tweak can be performed in less than 5 minutes.

How to Add Google Adsense or an Affiliate Banner Above Blogger Blogspot Header
How to Add a Google Adsense Ad Unit or an Affiliate Banner Above the Blogger Header

1. Login to Blogger if not already logged in

2. Navigate to Layout > Edit HTML

3. As a precaution back up your template by downloading the full template to your computer

4. Tick the Expand Widget Templates box

5. Using CTRL + F to bring up the search box find this line which in most templates will be directly after <body> tag

<div id='outer-wrapper'>

6. Paste this block of code after this line to create a new section

<div id='topads-wrapper'>
<b:section class='topads' id='topads' preferred='yes'/>

7. Next we need to add some CSS styling to the new section. Please note that the banner will be centered by default. If you want to change the alignment for some reason you just need to change the CSS styling.

Place the following code in the head section of your template before these lines:

/* Top Ads
----------------------------------------------- */
#topads-wrapper {
margin: 0;
padding: 0;
position: relative;
text-align: center;
width: 100%;

#topads {margin: 0; padding: 0;}

#topads .widget {margin: 0; padding: 5px 0;}

8. Click the Save Template button

9. Go to Layout > Page Elements

10. You will now see that you can add a gadget to a new section above your header and directly below the navbar.

11. To Add a Google Adsense Ad Unit
Click on Add a Gadget and choose your desired Google Adsense ad unit. If you are uncertain how to add a Google Adsense ad unit to Blogger read my article Google Adsense Tips for Blogger Blogs

To Add an Affiliate Banner
Or if you want to add an affiliate banner then you would click on Add a Gadget and choose a HTML/Javascript widget from the list of gadgets available in the menu. You would then paste the affiliate banner code into the content box in the popup window and save your changes. Click on View Blog and you will see your new banner displayed above your blog's header. For more detailed instructions about adding affiliate banners to a Blogger Blogspot blog please refer to my article Add an Affiliate Banner to the Blogger Sidebar

Tips and Troubleshooting
  • If you wish to add more than one widget to the section you will need to change the template code:

    <b:section class='topads' id='topads' preferred='yes'/>

    <b:section class='topads' id='topads' maxwidgets='3'>

    This change to the template will allow you to add up to 3 widgets above the Blogger header.

  • If you wish to display your Google Adsense ad unit only on the post page and not the home page then you need to add an if statement. For instance go to Layout > Edit HTML after you have created your ad unit and you will see that the code you inserted is now different. That is because the Adsense widget code has been added. You are likely to have something that looks like this:

    <b:section class='topads' id='topads' preferred='yes'/>
    <b:widget id='AdSense7' locked='false' title='' type='AdSense'>
    <b:includable id='main'>
    <div class='widget-content'>

    By inserting the code within an if statement we can control where it appears. To have the Google Adsense ad unit only display on the post page add these lines of code:

    <b:section class='topads' id='topads' preferred='yes'/>
    <b:widget id='AdSense7' locked='false' title='' type='AdSense'>
    <b:includable id='main'>
    <div class='widget-content'>
    <b:if cond='data:blog.pageType == "item"'>

In today's tutorial you have learned how to create a new section above the Blogger Blogspot header and how to add a Google Adsense ad unit to that spot or an affiliate banner. You have also learned how to place that Google Adsense unit or banner only on the post page rather than on every page on your blog. Any questions please ask.

Related Articles
List of Blog Know How Tutorials for Blogger Blogs
Blogspot Blogger Guide to Google Adsense Placement
Google Adsense Tips for Blogger Blog
Add an Affiliate Banner to the Blogger Sidebar

Subscribe to Blog Know How by Email


search engine placement said...

Wow, great information. I could say my knowledge in seo is already broad but I find it nice to see people giving out tips and new information.

The Whizz said...

Thanks search engine placement. Glad to have you reading along

Sue & Zach said...

This is excellent, thank you.

Just one thing I'd like to mention though, in steps 5 & 6 I had to replace &lt with < for it to work in my template.

The Whizz said...

Hi Lupine Storm. There is no problem with the code just your internet browser is not reading it properly. HTML is OK in Internet Explorer but not in Opera, Safari, Sea Monkey and Firefox. Your browser is reading < as &lt and > as &gt. If you need to decode any code on this blog try copying and pasting the code into the box at Centricle and then clicking on decode.

L.J. Williamson said...

Super helpful, thank you. I just needed to do the same fix, replacing &lt with <
Other than that, it was terrific and just what I was searching for.

The Whizz said...

Great to hear this was exactly what you needed for your blog L J Williamson. Thanks for letting me know that the code is still being displayed in your browser incorrectly. I have tried tweaking it to improve things.

Anonymous said...

Oh my God !!! Thank you thank you thank you so much I am soooooooo grateful for this information. I have been searching the net for weeks trying to get this info and YOU were the only one who gave me details that actually worked. So once again thank you !!!!

The Whizz said...

Nichemaker you are very welcome! I am glad that this post solved a problem for you. I got the idea to write it from one of my readers. If there is something that you would like to know how to do that isn't already covered by this blog please ask and I will consider writing a post about it.

snam said...

It displays this "/* Top Ads ----------------------------------------------- */ #topads-wrapper { margin: 0; padding: 0; position: relative; text-align: left; width: 100%; } #topads {margin: 0; padding: 0;} #topads .widget {margin: 0; padding: 5px 0;}" at the top of my blog, but other than that it works great! Does anyone know how to remove this? My blog where I am testing this is

The Whizz said...

Snam I went to your blog but I couldn't see the top ads displayed so it is difficult to see what the problem might be. If it is displaying "/* at the top make sure you get rid of the double quotes. Dumb question but do have you got the /* Top Ads code in the CSS styling section only. The styling should not be anywhere else in the template. If you need me to take a look at it either join my email subscribers or leave your email and I will get in touch.

Debra said...

Thank you so much! You've walked me through it and everything went great! :-)

The Whizz said...

A Frugal Friend congratulations on successfully adding a banner to above the header. Hope to see you here again

sarasophia said...

Worked famously...thank you SO much! You explained this in perfect "beginner terms"<3


The Whizz said...

Hi Sarasophia. Glad to hear you got your banner working easily. Hope you will stop by again!

Guy said...

worked like a dream, thanks

The Whizz said...

Good for you Guy! Hope you will drop by again.

RnF Tech said...

thanks for the wonderful post buddy keep posting more like this...

এডমিন said...

What a Great tip!. I just added an adsense block with this tip above by blog ( header.

خالد محمد (ابوخلود) said...

oh my god ,wwwoooo. thank you very much you are great .
but i have problem when i want to add 3 widget to the section . the template tell me error when i added this code (maxwidgets='3'), plz tell me my problem .

The Whizz said...

Sorry cant say without seeing your blog and can't access it from the link you gave. What template are you using?

Post a Comment