Site logo

Archived topic

Want to add search box

7 replies · Started by John on December 22, 2019

Viewing posts 1–8 of 8

Hello

I want to add search box in homepage hero banner area.

I want to display search box instead of "Lets Get Started" button.

How can I do this?

Thanks

Added this code


function wpbsearchform( $form ) {
 
    $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
    <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
    <input type="text" value="' . get_search_query() . '" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
    </div>
    </form>';
 
    return $form;
}
 
add_shortcode('wpbsearch', 'wpbsearchform');

Then added [wpbsearch] in header element.
It shows.

I want to add some style. Want to add placeholder text like " Search Better Product"

And want to keep search box background transparent.

1. You can add placeholders in your code - edit this line:

<input type="text" value="' . get_search_query() . '" name="s" id="s" />

to:

<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="Your placeholder text here" />

2. Try this CSS to style search field background:

.toolzview_sarchbox input[type=text] {
    background-color: rgbas(255,255,255,0.5);
    min-width: 220px; /* Set minimumn width to cover mobile */
    width: 50%; /* Set width for all devices */
    margin-right: -5px; /* Remove margin between inputs */ 
}

Works fine.

Now, Want to remove blank space between search box and submit button.

And, If I want to increase search box width, how can I do this?

Updated the CSS here

Thanks a lot David. Your support is great always.

Glad to be of help :)

This archived topic is closed to new replies.