How to add default search in wordpress any page. - WPTRINITY

How to add default search in wordpress any page.

A search bar is very important for your website. Website user/visitors can find whatever they need in a moment using it. Basically, a search box is the Google search of your website that lets your users find important things quickly inside your site. This post is about the easiest ways to create a search bar in WordPress sites.

In most of the WordPress themes, a search panel is included by default. But if any theme doesn’t have it or you want to make your own custom search box, you can easily do that too. WordPress is well renowned for its customizability so there are different procedures to add a search bar to your website. Let’s do it together.

How to display the WordPress default search bar.

To display the WordPress default search bar you need to copy the following code and past in your Php file template where you want to use the default search bar on your websites.

get_search_form( array $args = array() )
// Display search form. 

You Can convert your custom HTML form functionally the same as WordPress default search bar
for this you need to change some attribute inside your custom from just like the below code.

<form role="search" method="get" class="search-form" action="/" >   
<div class="form-group">  
   <label for="exampleInputEmail1">Email address</label>
     <input type="text" name="s">     
    <button type="submit" class="btn btn-primary">Submit</button>

In this custom form, you need to add some additional attribute in the form tag.
<form role="search" method="get" class="search-form" action="/" >

and in the text field, you add name attribute with “s” string.
<input type="text" name="s">

Leave a Comment

Your email address will not be published. Required fields are marked *