Here’s how to add a responsive search form to the header of Twenty Twelve theme.
Create a child theme before doing this, modifying parent theme template files only causes problems later on.
Copy header.php to your child theme directory and open it.
Find the line that reads
|
1 |
</hgroup> |
Copy this directly below it
|
1 |
<div class="header-search"><?php get_search_form(); ?></div> |
Save and close header.php
Open style.css and add this to it
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
.header-search { float: right; margin-top: -50px; } @media (max-width: 650px) { .header-search { margin-top:5px; text-align:center; float:none; } .main-navigation { clear:both; } } |
Save and close style.css and view your site and it should look just like the one at the top of this site. (removed to make room for adsense)
Hi Zeaks,
Thank you for making this post and it was exactly what I was looking to do. I am having a problem getting the search form to move to the right hand side of my theme. I have downloaded your child theme, copied and amended the head.php file and added the sample code to the style.css
Any help would be appreciated.
Thanks
Matt
Hi Matt, looks like you have the searchform floated left, change it to float: right like this
I forgot that I had changed that setting. I was trying to see if aligning it left then right would make a difference.
When you said add it to the style.css then I am assuming that you mean the one in the child theme?
I have cleared the browser cache, tried different browsers, disabled any caching, but I cannot get it to align to the right. Any ideas?
Thanks Matt
I have worked out what is happening. My provider seems to be doing some form of caching and I have felt it for a few hours and now its working.
Great article and thanks for assistance.
Matt
Glad you sorted it out Matt
Hello,
I used this code to move my search bar on the right side,
but when I go to my site in internet explorer it still sits on the left, over my logo
any ideas on how to fix this?
Hi Mario, try this
Didnt work :/
I realized that twentytwelve (im using a child theme) has its on ie.css that comes into play when wordpress reads internet explorer, i tried to see if theres a conflicting code in there but nothing seems to work towards the search widget.
my whole site looks fine in internet explorer, its just the search bar that refuses to move.
i mean the original coding from this post worked to get it right where it needs to be in chrome, and firefox, as for internet explorer the code worked to get my search to display in the header, but it refuses to move over the search bar.
the site is Mixx Shuz
Hi Mario, try adding it to the bottom of the style.css if you’ve added other CSS to your child theme. This is the same code I’ve used in the Twenty Plus Pro theme http://zeaks.org/ttodemo and the search displays as it shoul din FF, Chrome, IE 7-10
I’d also disable any plugins you have active to rule them out as a possible problem.
yea, tried that too.
this is ridiculous, im sure its just a small piece of conflicting code but i cant seem to find it.
If you want to send me a copy of your child theme, I’ll take a look on my test site and see if I can figure out the problem. Debugging for IE is a pain sometimes. Use the contact form at the top if you want to do this.
Would it be possible to modify this to insert a logo as opposed to a search box in the upper right, adjacent to the site title?
Hi Sky, yes this would work, but you might want to take a look at this post which only requires the use of CSS. http://zeaks.org/tutorials/how-to-add-a-logo-to-twenty-eleven-theme/ replace the #site-title ID with .site-header h1 a and use the text indent on the .site-description if you want to hide that as well for Twenty Twelve.
Thanks so much! I’ll give it a try tomorrow and let you know if I was able to figure it out!
Hi Scott,
thanks for this tutorial!
Do you have any suggestions how to place the header-search div on top (not above) the header image (so the search form would be ‘inside’ the header image) in a twentytwelve child theme?
Thanks again!
Hi Fixer, you could try adding it within the hgroup. Place it before the closing tag, then adjust it as needed.
Hi Zeaks. Thanks for your post (which I followed successfully to make some mods!). I’m working on re-designing my site using twenty twelve and am having some trouble getting my head around certain aspects. Do you mind telling me how you got your header to spread right across the page like that, pls? Will that appear OK on cellphone screens and iPads etc?
Cheers!
rolanstein
Hi Rolanstein, this site does not use Twenty Twelve, it’s using a child theme of the new upcoming default theme Thirtyten. If you download a nightly build you can take a look at the files to see how they did it. I haven’t had a chance to view it yet myself.
I would imagine it’s just a very wide header image 1600px that scales to fit the device it’s viewed on by using max-width.