Home Post Index SEO Tools FAQs Contact Donate

Add banner, Adsense or search box in header

Wednesday, May 12 | 82 comments

header with search box

A reader asked me how to add a search box on the right of blog title. I thought I’d share my answer in this post.

Actually, you can add anything inside your header -be it an ad banner, a search bar, social media buttons, Adsense ad or just about any widget you can get your hands on. But how?

By simply adding a section in the header. A section is a widget container of sorts, indicated by a light colored box in Page Elements tab and usually comes with an Add A Gadget link thingy. Once you have the Add A Gadget added in there, the rest is easy.

Here we go:

 

1. Adding a section (in HTML)

  1. Login to your Blogger account.
  2. Go to Dashboard > Design > Edit HTML.
  3. Back up your template.
  4. Make sure the Expand Widget Templates checkbox is UNTICKED.
  5. Look for the following lines in your HTML code:
    <b:section class='header' id='header' maxwidgets='1' showaddelement='no'> 
    <b:widget id='Header1' locked='true' title='My Test  Blog (Header)' type='Header'/> 
    </b:section>
  6. To add a section, insert the following code right under (after) it:
    <b:section id='header-right' showaddelement='yes'/>
    <div style='clear: both;'/>
  7. So the final code should look like this:
    <b:section class='header' id='header' maxwidgets='1' showaddelement='no'> 
    <b:widget id='Header1' locked='true' title='Blogger Sentral Widget Showcase (Header)' type='Header'/> 
    </b:section> 
    <b:section id='header-right' showaddelement='yes'/>
    <div style='clear: both;'/>

You now have two sections in the header, the section with the existing blog title on top and the new section below it.

 

2. Styling the section (in CSS)

Position the sections side by side, by floating the section containing the blog title to the left,  and the new section to the right.

To achieve that,

  1. Locate this line of code (you are still on Dashboard > Design > Edit HTML page):

    ]]></b:skin>

  2. Add the following CSS code right before (on top of) the line.
    #header {width:50%;display:inline-block;float:left;}
    #header-right {width:35%;display:inline-block;float:right;padding:15px;}
    #header-right .widget {margin:0;}

 

3. Installing the widget

Now it is time to add the banner, search box, Adsense ad unit or whatever. Do as you’d normally do when you want to install a widget,

  1. Go to Design > Page Elements.
  2. Click the new Add A Gadget link and add your widget.
    split header Note: The header wireframes may not appear side by side for Designer templates, nevertheless they should show up just fine on your blog.
  3. Save and view your blog.

 

4. Fine-adjusting the position

If the added widget shows up under the blog title (instead of on the same level, on it’s right), go back to the CSS code in step 2.2.

Change header(code line 1) and header-right (code line 2) widths. Experiment with different values until you get it right.

 

Enjoy!

82 comments to "Add banner, Adsense or search box in header"

Marly May 13, 2010 9:20 AM  

I think it's great that you provide this instruction to people. I'm lucky because my husband is a website designer, but I know with a little hard work I could figure things out. Especially with wonderful people like you who share what you know. The more we can help each other the better, eh? What's the saying? A rising tide lifts all ships!

Greenlava May 13, 2010 6:12 PM  

@Marly
Thanks...I always believe what you give, you get back, somehow :)

@Anup
My pleasure

Metilparaben May 13, 2010 8:36 PM  

Thank tou for the article: I tried to install the widget, but the right header section comes below the title image, even if on the right, also when i save and look at the blog. Any idea?

Greenlava May 13, 2010 10:07 PM  

@Metilparaben
I've modified the CSS code slightly, see if that solve your problem. BTW which blog are you installing the widget to?

Metilparaben May 14, 2010 12:52 AM  

http://metilparaben.blogspot.com/
I'm going to try your new code: I'll tell you!
Thanks a lot!

Metilparaben May 14, 2010 12:58 AM  

No way, same problem. The widget goes under my header: You can see it here.

Greenlava May 14, 2010 1:30 AM  

@Metilparaben
Could you leave the widget there for a while, so I can take a look at it?

Metilparaben May 14, 2010 7:23 PM  

An another thing: even if i reduce the lenght of the widget, decreasing the number of the buttons, the space between the end of the header and the first post increases a bit...

Metilparaben May 14, 2010 7:23 PM  

Yes, i put it in my draft blog:
http://metilparamusic.blogspot.com/
I succedeed in putting the code in the right place, so that the header and the widget come one besides the other, but as you can see the widget doesn't fit in the space, and moreover the header image is cut...

Metilparaben May 14, 2010 7:27 PM  

Ok, guess i succeeded in modifying slightly the code (paddings etc.) and made it! Thanks a lot!

Metilparaben May 14, 2010 7:50 PM  

No. Nothing. When i put the same code in my real blog, even if the template should be just the same of the other (except for some slight differences) the widget goes back down. And look: the "add a gadget" box that you show in this post is shown half the width of the above header... Don't understand.

Greenlava May 14, 2010 10:04 PM  

@Metilparaben
I managed to "catch" your layout just now, when you added the buttons.
1. It seemed you left out the #header part of the CSS code in 2.2
2. You also need to change padding:15px; to padding:0 15px. And increase the width from 300px to 400px.

Philippe Tyrode May 27, 2010 1:24 PM  

Thank you for the article. I tried to install the widget, but the right header section comes below the title image, even if on the right, also when i save and look at the blog. Can you help me ? http://geekastuces.blogspot.com

Philippe Tyrode May 27, 2010 4:11 PM  

Hello,
Thank you for the code. This works fine on Firefox. For Internet Explorer it causes deviation in header. For exemple with http://motdecas.blogspot.com/
Thank you very much for your help

Greenlava May 27, 2010 7:58 PM  

@Philippe Tyrode
In 2.2 #header, try removing the underscore in _float:left;

DClass Blogger May 28, 2010 12:57 PM  

I've tried to follow the above instructions, and even made some changes in padding, and realize I have two adsense gadgets. I could use your help. Thanks. http://bankruptcydirectory.blogspot.com/

Greenlava May 28, 2010 5:05 PM  

@DClass Blogger
Welcome to Blogger sentral...
1. Remove the extra Adsense gadget
Go to Layout>Edit HTML and make sure you the Expand Widget Templates checkbox is UNTICKED. Then find and delete this line of code:
[b:widget id='AdSense1' locked='false' title='' type='AdSense'/]
Preview before saving.

2. Making the blog title and Adsense sit side by side.
Reduce the paddings from 50px to 10px:
#header-right {width:40%;display:inline-block;float:right;padding:0 10px;}
Preview before saving.

DClass Blogger May 29, 2010 12:06 PM  

Greenlava,

This is a step forward. Thankyou! However, I am still stuck. When I go to Layout > Page Elements and look for the new Add A Gadget link, there isn't one there. The Page Elements show the (Header) as a full box, not a split box which I was expecting to see. Am I missing something? As you can see on the blog itself there is a space for the gadget, but the Page Elements shows no split?

Thanks for walking this out with me!

Greenlava May 30, 2010 2:17 PM  

@DClass Blogger
Hmm...that's odd.
Anyway let's start over by removing the 2 header-rights that you added. This time tick the Expand widget Templates checkbox, find and remove these (2 instances):
[b:section id='header-right' showaddelement='yes'/]
[div style='clear: both;'/]

Once removed and saved, put the section back by following the instructions in this tutorial.

Brian July 1, 2010 8:02 AM  

Hi, I am having a similar problem with the new section appearing beneath the header. I've triple checked the code, and redone it a number of times, no luck. Any ideas for me?
See here http://activistposttest.blogspot.com/

Thanks.

Greenlava July 2, 2010 7:37 AM  

@Brian
Adding this code in 2.2 will fix that:
.header-inner .section {margin: 0 0 0 16px;}

KellyRewards-Steve July 5, 2010 3:35 PM  

Hey. I am having trouble. My banner is showing up under my header. Can you tell me why?

Here is the link:
http://kellyrewardsblog.blogspot.com/

Greenlava July 5, 2010 6:32 PM  

@KellyRewards-Steve
I've revised the CSS code in Step 2.2. Try it out.

cvblogs July 10, 2010 1:40 PM  

Thank you very much for posting this. Appreciate it a lot!!
SMILES!!!

David July 31, 2010 11:22 AM  

Hi!

I'm just wondering if this can be applied to the new template designer?

Thanks

Greenlava August 1, 2010 7:48 AM  

@David
Yes this is applicable to both the (old) layout template and (new) template designer.

Christine@Christine's Recipes August 2, 2010 9:29 AM  

Thanks for your amazing tutorial.
I've tried many times to install the code, yet found the new section still beneath the blog title, not side by side.
Could you take a look at my blog to see what's the problem:
http://testchristinesrecipes.blogspot.com/

Thanks in advance.

Greenlava August 2, 2010 10:48 AM  

@Christine@Christine's Recipes
You mistakenly place the CSS before the closing tag of the last existing CSS code:
line-height:1.4em;
#header {width:35%;display:inline-block;float:left;}
#header-right {width:50%;display:inline-block;float:right;padding:0 10px;}
#header-right .widget {margin:0;}
}

should be like this:
line-height:1.4em;
}
#header {width:35%;display:inline-block;float:left;}
#header-right {width:50%;display:inline-block;float:right;padding:0 10px;}
#header-right .widget {margin:0;}

And to make the ad fit snugly inside the header you want to change header width to 22% and header right to 74%.
Oh one more thing, do view in different browsers and adjust accordingly.

Christine@Christine's Recipes August 2, 2010 11:34 AM  

Hi Greenlava,

Your suggestions worked and the headers fitted perfectly. THANK YOU so much.

However, I found the link list underneath squeezed to the far left and placed vertically, not horizontally. Is there anything wrong with the code?

Greenlava August 2, 2010 12:47 PM  

@Christine@Christine's Recipes
Looks okay from here, in Firefox, Chrome and IE.

Christine@Christine's Recipes August 3, 2010 8:53 AM  

Hi Hi Greenlava,
Sorry for bothering you again.
It's not ok on my side, in Firefox. But it's fine in IE. Very weird. Here's the screenshot:
http://lh5.ggpht.com/_V0CoK16CILc/TFdnyNPJV6I/AAAAAAAAI3g/EZlKRvteNfs/s1024/Tabs%20shifted.JPG

Greenlava August 3, 2010 1:34 PM  

@Christine@Christine's Recipes
I see it now (had to zoom in to see it though).
Somehow the -1px top margin of your tabs is causing the shift.
To fix it, go to Design > Edit HTML and look for this code:
.tabs-inner .section:first-child {
border-top: 1px solid #ebebeb;
}
.tabs-inner .section:first-child ul {
margin-top: -1px;
border-top: 1px solid #ebebeb;
}

you want to remove the top border (the first one) and negative top margin.

vijji August 3, 2010 9:59 PM  

Thank u very much, me added search box to my blog, thank you......

http://www.e-bookstore4u.blogspot.com/

Daniel.James August 6, 2010 11:38 PM  

hello, been reading this tutorial and have followed exactly. I have the same problem with the widgets below the header, I have looked at the following code.

".header-inner .section {margin: 0 0 0 16px;}"

This still is not working. I am using the new template desinger in Google. I want the widgets to be level so there is no problems in web broswers. Firefox looks fine, sometimes Internet Explore the gadgets move down.

The site might look fine but i dont want to take risks, so I want to eliminate the problem bye leveling the widgets side by side

The url is webexploits.co.uk

thanks you

Daniel James of Web Exploits

Steve August 10, 2010 12:21 AM  

Help! I want to put a slideshow gadget beside my header, not under it. I have tried to split the header template by following all the steps and the suggestions made in the comments section, but each time I click on the Page Elements tab, there is only one box on the header line (though recently it is centered instead of going all the way across). My blog is www.esseffbee.blospot.com.
Can you help?

Greenlava August 10, 2010 1:53 AM  

@Steve
This is the CSS code you added:
#header {width:30%;display:inline-block;float:left
#header-right {width:66%;display:inline-block;float:right;padding:0 15px;}
#header-right .widget {margin:0;}
.header-inner .section {margin: 0 0 0 16px;}

the first line doesn't have a closing curly bracket -that's the problem.
Use this code instead:
#header {width:30%;display:inline-block;float:left;}
#header-right {width:66%;display:inline-block;float:right;padding:0 15px;}
#header-right .widget {margin:0;}

notice I also remove the last line.

Steve August 10, 2010 2:48 AM  

Brilliant! I am amazed that the problem was so simple. I thought I was being so careful . . .

Mysticle August 11, 2010 2:05 PM  

Another great tutorial! I have added the widget successfully, to the right of my header. However, I want the widget above my header image. I am not attempting to install adsense - what I want is to add tabs above my header (as I have done using an html widget below my header). I've seen this on other blogs.

Thanks, Misty

http://mysticle.blogspot.com/

Mysticle August 11, 2010 2:19 PM  

.... after a little more tweaking, I managed to achieve the result I wanted. I placed the new widget above the header, and expanded width on both to 100% - worked perfectly.

Thanks again for all of your great tutorials!

~ Misty

Damon August 14, 2010 4:56 AM  

Is it possible to style the new widget section so that it is positioned above the main header?

Michael August 14, 2010 11:17 AM  

hey greenlava, thanks for this tutorial... i've followed the instructions and i think they work just fine. keep up the good work... people need this kind of stuff... your way of giving out info/instruction is one of the few that's easy to understand.

http://yourlooktoday.blogspot.com

my site is still under construcstion... im just experimenting with stuff... i plan to put an ad on my header, so right now it's still an empty space

Greenlava August 15, 2010 8:19 PM  

@Damon
To add a widget above the header, don't use this hack.
Instead, use the method below:
1. Go to Design > Edit HTML. Do not tick the Expand Widget Templates checkbox.
2. Look for this code:
[b:section class='header' id='header' maxwidgets='1' showaddelement='no']
and rep1ace it with this:
[b:section class='header' id='header' maxwidgets='' showaddelement='yes']
3. Go to Design > Page Elements. Look on top of the header -you should now have a Add-A-Gadget link there.

Mary August 18, 2010 8:06 AM  

Have you got any suggestions for me?
(http://blogger-hints-and-tips.blogspot.com/)

I think I followed the instructions, but when I look at Design > Page Elements, the header gadget still takes the full width.

But I found (by experimenting) that if I added a HTML gadget to the top of the page-tab area, it gets put into the header - but with ugly looking borders as you can see with the Amazon ad in my header now.

I added the ugly table-borders around the translate gadget/web-element (which are in a HTML gadget that's in the header), so I could see where the header ended.

I've tried all sorts of options, but nothing seems to work re giving the new right-header good margins.

Any thoughts?

Greenlava August 18, 2010 10:17 AM  

@Mary
You can change the margin by changing the value of padding in 2.2 line 2.

Anonymous,  August 21, 2010 3:40 PM  

Hello GreenLava,

I installed this hack to my blog. Codes are working perfect but wrappers inside control panel looks like the image i attached. I want to adjust this.

Here is the image:
http://img412.imageshack.us/img412/7510/21815393.jpg

Greenlava August 22, 2010 12:27 AM  

@Anonymous
I'm still working on that issue. I'll update as soon as I come up with a fix.

Selina August 23, 2010 6:36 AM  

Can you please tell me how do you put adsense inside your posts. I only get more empty space in my posts when i add this code. Is it possible to just put them inside the posts without putting them in between the posts?
code:

[b:if cond='data:blog.pageType == "item"']
[div][script type='text/javascript'][!--
google_ad_client = "pub-xxx";
google_ad_host = "pub-xxx";
/* 468x15, created 8/22/10 */
google_ad_slot = "8886107604";
google_ad_width = 468;
google_ad_height = 15;
//-->
[/script]
[script src='http://pagead2.googlesyndication.com/pagead/show_ads.js' type='text/javascript']
[/script]
[/div]
[/b:if]
[div class='post-footer']

Tnx again greenlava

Greenlava August 23, 2010 9:45 AM  

@Selina
You put the ad code directly inside your template right? Well, you should've HTML-escaped the code first.
1. Go http://www.accessify.com/tools-and-wizards/developer-tools/quick-escape/default.php
2. Paste in your code
3. Click the button and copy your escaped code.
4. Paste the code in your template.

Remember to escape your Adsense code everytime prior to putting it in your template.
Putting a code inside a HTML/Javascript widget or in a post needs no escaping.

Selina August 23, 2010 6:24 PM  

Life saver as always. Thanks for everything really. Gona do some retweeting of your posts, i already put your link in my bloglist, hopefully that link will worth much more with next page rank update :).

Juliet August 29, 2010 12:33 PM  

Your tutorial is awesome, but it isn't working for me for some reason. The new section always appears under my header for some reason. Any advice based on my particular blog layout? (my site is yummy diet food).

Greenlava August 29, 2010 12:42 PM  

@Juliet
That's because your existing header image occupies the full width of your header already.

usey August 29, 2010 1:05 PM  

Hi Greenlava, I've tried the tweaks but my gadget is still appearing below the title. Can you please have a look?

Greenlava August 29, 2010 4:48 PM  

@usey
You template is a bit different, the #header is named #blog-title. And the outer container is set to 400px whereas your blog width is 1000px.
Anyway, try replacing the code you added with this one:
#blog-title {width:210px;display:inline-block;float:left;}
#header-right {width:725px;display:inline-block;float:right;padding:0 10px;}
#header-right .widget {margin:0;}
.blogname {width:960px;}

usey August 29, 2010 6:24 PM  

Thanks Greenlava! Just tested and all looks good now, and thanks for the quick reply, really appreciate it :) Keep up the good work.

LaniXs August 29, 2010 10:38 PM  

Hello Greenlava I found your site and I follow all your instructions.. But I couldn't just put it to the right of my header title.. can you check my code please??

Thanks!

Greenlava August 30, 2010 1:31 AM  

@LaniXs
Use this code instead:
#headerleftsect {width:40%;display:inline-block;float:left;}
#header-right {width:50%;display:inline-block;float:right;padding:0 10px;}
#header-right .widget {margin:0;}

LaniXs August 30, 2010 8:36 AM  

Thank you so much bro now its working.. You really are professional,great skills.. Thank you so much for helping people bro..

d September 1, 2010 2:59 PM  

I'm using simple ii template by jason sutter. it was released in 2006 by blogger. i want to embed search box within its header at the right side. is it possible? i tried your above codes. it worked for minima stretch template. But it doesn't work for simple ii template. I would like you to give me solution(if you know) to embed search box within header of simpleii template by Jason Sutter.

my blog: http://ramasamydemo.blogspot.com/

Greenlava September 1, 2010 8:04 PM  

@d
1. Go to Design > page Elements and add in Search Box gadget. Then reposition it (drag and drop) under header gadget.
2. Go to Design > Edit HTML and add this code right before ]]>< /b:skin>:
#Header1 {float:left;}
#CustomSearch1 {float:right;clear:none;}

D Class Blogger September 3, 2010 7:12 AM  

Hi Greenlava,

I've haven't given up on splitting my header, but it does feel like I'm hitting my head against the wall. I've contacted you before for your help, and I've tried following your tutorial again, several times. However, I realize that I've done something wrong. I've noticed that you've helped a lot of people, and I would ask that you revisit my site, to help me with my second header. I've tried to make it appear in the page elements, but I'm not getting anywhere. I've tried adjusting the widths, and even the padding, so I need help! If you could suggest how I can accomplish this, so that I can also join your roster of successful candidates, I would greatly appreciate it.

Greenlava September 3, 2010 3:04 PM  

@D Class Blogger
I'm seeing the headers are sitting side by side already (albeit the 5% widths). Not sure if you can see that in Page Elements.
Try setting the widths to 35% for the header and 60% for header right.
To see for yourself if it works or not (in normal view), use the new Add A Gadget link to add any gadget into header right. Then view your blog.

d September 3, 2010 8:37 PM  

i fixed the search box within header at the right side by your help. Thanks Greenlava. But, I have a doubt.

can I add a HTML link too within header at the right side of header by puttin a similar code like #Header1 {float:left;}
#CustomSearch1 {float:right;clear:none;} before bskin?

Let us consider the widget id of new HTML link I am going to add be HTML3. if i want to put it within header at right side below search box is it possible if I add code like HTML3 {float:right; clear:none;} just after the codes

#Header1 {float:left;}
#CustomSearch1 {float:right;clear:none;}

I mean I want to add a HTML link too below or above search box which is already fixed within header...
is it possible?

Greenlava September 4, 2010 2:35 AM  

@d
Yes you can. If you place HTML3 below the search box, use this CSS code:

#Header1 {float:left;}
#CustomSearch1 {float:right;clear:none !important;}
#HTML3 {float:right; clear:all !important;}

as you can see, clear:all is for the bottom widget clear:none is for top widget.

d September 4, 2010 11:36 AM  

If I want to place the link of HTML3 above search box at the right side within the header of simple ii template should I use code like the following one? is the following code right?

#Header1 {float:left;}
#HTML3 {float:right; clear:none !important;}
#CustomSearch1 {float:right;clear:all !important;}

d September 4, 2010 12:59 PM  

#Header1 {float:left;}
#CustomSearch1 {float:right;clear:none !important;}
#HTML3 {float:right; clear:all !important;}


in the above code if i drop the last line of code for HTML3 the search box will be at right side top corner. i like its placement. suppose i dont need html3 link now within header. at this point shall i use just the first two line of codes...that is for placing search box at top corner at right side and without html3 shall i use just this code

#Header1 {float:left;}
#CustomSearch1 {float:right;clear:none !important;}

We love to hear from you! Leave us a comment.

If your question is unrelated to this article, please use our Facebook discussion board.
When posting HTML/XML code, replace < and > symbols with [ and ] respectively.

Share

Get this
Click to go to top Click to comment