I created a function to display a search box and named it my_get_search_form(). That is a copy of original get_search_form() function.

When I call the function, the output is this: Search in http://localhost/wp_ex_3/ <AN EMPTY BOX> <A BROKEN IMAGE LINK>.

How can I change this ugly display and to not show http://localhost/wp_ex_3/. I should to say that in the function definition there is not "search in" statement so another function caused this behaviour. source code of the function on developer.wordpress.org: https://developer.wordpress.org/reference/functions/get_search_form/#source-code .

  • Why do you need another function to call the same searchform.php? – Mayeenul Islam Dec 15 '14 at 15:24
  • @MayeenulIslam I want it so that I can change its structure whitout changing the original function, for example maybe I want to add another box to the formset, something that by using the get_search_form() cannot achive. – gary Dec 15 '14 at 15:28
  • To change the searchform you don't need to mess with get_search_form(), you just need to create your own search form in your theme and name it to searchform.php. You can see this: wordpress.stackexchange.com/a/165494/22728 – Mayeenul Islam Dec 15 '14 at 15:32

you don't need to add another function to get the search form. If you want to change the look of the search form or add another items you'll have to add the searchform.php to your theme.

It could look like this:

    <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
        <input type="search" class="search-field" placeholder="Suchen …" value="<?php echo get_search_query() ?>" name="s" title="Suche nach:" />
        <input type="submit" class="search-submit" value="Suchen" />

Everytime you call the get_search_form() function it will return the content of the searchform.php file. There you can add as many form fields as you wish.


If you want to change the search behavior, then, all you need to do is add your own fields to the form

<form role="search" method="get" id="searchform" action="http://www.test.dev/">
<label for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
<input type="hidden" value="1" name="sentence" />
<input type="hidden" value="product" name="post_type" />
<input type="submit" id="searchsubmit" value="Search" />

This search form, when submitted, will generate the following URL:


Changing default behavior or Search Form is necessary depending on Theme Design. Here's an example what I do:

add_filter('get_search_form', 'elevation_search_form');

function elevation_search_form($form) {
    $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" class="search-form">
        <input type="text" name="s" id="s" class="search" placeholder="Search for.." value="' . esc_attr( get_search_query() ) . '" required>
        <button type="submit" id="search-submit" class="search-submit"><i class="fa fa-search"></i></button>
return $form;
  • 1
    It looks like this will give PHP syntax error. Can you please update your answer, thanks. – birgire Mar 1 '17 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.