Adding a Search in the header?
-
How do I add a search in the header right above the Tag line
-
Yep:
#searchform { max-width: 300px; position:relative; top:30px; right: -110%; } .searchform input[type="text"] { width: 50%; } .searchform label[class="screen-reader-text"] { display:none; }
The “position:relative; right: -110%” is what I need to get the alignment how I want it in a 1267px wide viewport. But things go wrong quickly from there.
I’ll try another if I may: how can I replace the “searchsubmit” (black rectangle containing the word ‘Search’) with a magnifying glass icon? Or is that a different topic?
I’m trying something different to your issue, and about the serach submit, mind if the magnifying glass is not clickable? Just an icon..
Aesthetically I would be happy with a non-clickable icon but I don’t think it will work as a UI since most visitors will not be too computer-savvy so won’t automatically hit Return… So, on balance, I would have to stick with the clunky black rectangle (albeit, I can change its colour).
BUT…I suppose I could populate the text field with something like “Enter search term and press Return” – so then we could go with an inert icon…
Yep, but the bad thing is that I can make that button transparent, but cannot remove the border, don’t know why.
So you can use a background image for it with that magnifying glass.
Anyway that’s what you have to do to start (you have to do proper media queries for max-width: 769px, for example assigning to tc-header a margin-top of … what you need), but you have to adapt it to your case.
Let’s start with your request about the searchinput.
In your child theme create a file named: searchform.php:<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>"> <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="" /> </form>
In the snippet above, for the widget area, change this with this:
'before_widget' => '<div id="%1$s" class="widget %2$s">',
with this:
'before_widget' => '<div id="%1$s" class="widget %2$s container">',
That way the widget area will follow the “behavior” and size of the carousel, which has the same class.
Then replace this:
add_action('__navbar', 'add_navbar_top_widget_area', 1);
with this:
add_action('__before_header', 'add_navbar_top_widget_area', 1);
Ok, now we need some style, you clearly have to tune to fit your case.
In your child theme style.css:#navbar-top { width: 100%; float: none; margin-left: 0px; position: absolute; /* to put it virtually inside the navbar-inner */ top: 60px; /* needed 'cause navbar-inner has z-index 200 */ z-index: 210; } .navbar.notresp .row-fluid { /* leave the space for our searchbox*/ margin-top: 60px; } #navbar-top #searchform { max-width: 300px; float: right; } #navbar-top #searchform input[type="text"] { /* if you use percentage here something breaks*/ width: 200px; }
Hope this helps, and sorry if I don’t get your issue..
Wow! Thanks! That looks exciting!
I need a few minutes to play with it as I’m old and slow…
Sorry for this question but I’m a php virgin.
Do I have to put anything before your <form> code, like “<?php” ?
And, just double-checking but I need a new file for this – I can’t just add it to my existing functions.php child?
Nope, you don’t need that “<?php”.
And you mean always about the form?
Is a template you must have in your child theme in order to override wordpress search form. And it must be called the way I told you ??
https://codex.www.ads-software.com/Function_Reference/get_search_formOK, getting there… What I now have is a search form positioned exactly where I want it and which moves in perfect harmony with the right edge of my slider. That’s a truly wonderful thing and I am indebted to you.
Not everything is good though. The top level of my navigation menu no longer works either on hover or mousedown (it is coded to be clickable and also to produce any dropdown menu on hover). If I wait long enough, I do eventually get a dropdown menu (where one exists) and it works fine – but the top level functionality is broken.
When I inspected my top-level menu I got this:
<div id="search-3" class="widget widget_search container"><form role="search" method="get" id="searchform" action="https://localhost:8888/sitename/"> <input type="text" value="" name="s" id="s"> <input type="submit" id="searchsubmit" value=""> </form></div>
Does this mean that my menu is now part of a new hierarchy? Anyway, it doesn’t seem to like it.
I also still have a (smaller) black rectangle to the right of the search text field. It is interactive so behaves the same way as the original “searchsubmit” rectangle. Can I put a background image in here? (Not that I know how of course…)
Well.
Probably the thing is that you have to set a higher margin top for thenavbar.notresp .row-fluid
. Looks like the div we put overlaps the menu.
That rectangle is, as you said, the submit button. And you can set a background image for it. But.. it’s late here, and I have to go to sleep. We’ll think about that tomorrow ok?
Please open a new topic so we can do all that there :).
Goodnight.That fixed it, d4z_c0nf. Thanks again for all your help. Sorry you have to sleep – it’s only midnight here. The night is young. But I’ll be back for more tomorrow unless you need a longer break.
@d4z doesn’t sleep, he closes his eyes and absorbs even more Czr solutions for the next day. Only mere mortals like me sleep ??
d4z_c0nf,
thx for ur help and the code but i have one problem.widget_search the magnifier is on the left and the search box and the form is on the right of the page
yavarkhan would be good to see your site ??
What code did you use? The one I gave to Dibyendu?
The one I gave to chappie?
Probably you made a mix..?will upload the site in a weeks time!
- The topic ‘Adding a Search in the header?’ is closed to new replies.