banner-image

How to edit the WordPress Search form?

We can easily call the search form using the below function.

get_search_form();

But sometimes we need to edit the search form. To do that we have to use the below function on the active theme’s functions.php file. You can modify the forms HTML as per your needs.

//write this in functions.php file

function my_search_form( $form ) {
    $form = '<form action="home_submit" method="get" accept-charset="utf-8">
            <label for="search-field">SEARCH</label>					
            <input type="text" name="search field" value="Enter search here" id="search-field" title="Enter search here" class="blink search-field"  />
            <input type="submit" value="GO!" class="search-button" />
        </form>';
    return $form;
}

add_filter( 'get_search_form', 'my_search_form' );

Also, we can directly use the custom search form without calling the default search form function. Use the below code directly to show the search form.

<form action ="/" method = "get">
  <label for = "search">Search in <?php echo home_url( '/' ); ?></label>
  <input type = "text" name = "s" id = "search" value = "<?php the_search_query(); ?>" />
  <input type = "image" alt = "Search" src = "<?php bloginfo( 'template_url' ); ?>/images/search.png" />
</form>

 

For more details, visit this link.

Do You Want To Boost Your Business?

drop us a line and keep in touch