WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] add search box in header (10 posts)

  1. nun
    Member
    Posted 6 years ago #

    I'd like to add a search box to my header -- preferably next to the RSS icon. What coding is needed and where would I put it in header.php? Many thanks.

    Sister Julie at http://anunslife.org

  2. kulpreetsingh
    Member
    Posted 6 years ago #

    Hi Sister Julie,

    Please add this to your header.php file beside the RSS icon.

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    <div><input type="text" size="18" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" class="btn" />
    </div>
    </form>

    Let me know how it goes.

    God Bless :)

  3. krembo99
    Member
    Posted 6 years ago #

    What kulpreetsingh said is absolutly correct.
    I just wanted to add two small things for other people's sake also :

    1. if your template supports it you can just add :
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>

    2.adding the following code will put a text inside the search box.
    (like "Write your search and hit Enter" )

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    <div><input type="text" size="put_a_size_here" name="s" id="s" value="Write your search and hit Enter" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
    <input type="submit" id="searchsubmit" value="Search" class="btn" />
    </div>
    </form>

    and finally, combining those two advices, just save the code from part two as searchform.php in your template folder, and you can always call it with method number 1.

  4. kulpreetsingh
    Member
    Posted 6 years ago #

    Great points krembo99 :)

  5. nun
    Member
    Posted 6 years ago #

    kulpreetsingh and krembo99 -- Thank you so much for your prompt attention and assistance. I combined what you both said and came up with something that works perfectly. I think the green bar must have limits on it because when I tried to put the search box there it kicked it to the center of the line below. So I moved it up and I think it fits better there. I even tried the text in the box thing with a little biblical twist! :)

    I've only been on wp.org for the last week and so am brand new to this coding thing. It helped to have quick, straight up solutions from both of you. Many thanks! Blessings,
    Sister Julie

  6. kulpreetsingh
    Member
    Posted 6 years ago #

    Haha! Seek and you will find. This is true. :)

    Looks good. You can also style it with CSS if you feel so inclined.

  7. jamesspratt
    Member
    Posted 6 years ago #

    Hey,

    I'm also trying to do the same thing but place the Search box to the right of my header title. There's a bit of disused space there that I'd like to use instead of placing the search box in a sidebar.

    JamesSpratt.org

    Any help much appreciated.

    Cheers,

    James

  8. redsy
    Member
    Posted 6 years ago #

    I am trying to add the reverse, an rss icon into the header, any help appreciated. HIP-Consultant.co.uk

  9. Diesel12
    Member
    Posted 5 years ago #

    Thank you KREMBO!!!!

  10. callumalden
    Member
    Posted 5 years ago #

    great, simple solution- works a charm. can't be any better forum answer than that. thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic