WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to customize the default WordPress search field. So I thought I could add a filter to remove the function and then add in a new function with the fields the way I want them. So I tried this

 function savior_search(){
     <form role="search" method="get" id="searchform" action="<?php echo home_url( '/');        ?>">
    <input type="text" value="" name="s" id="s" />
<?php }

 add_filter( 'get_search_form', 'savior_search');

It seems to work but for some reason that I don't understand, it duplicates the search field. It puts the form on the page twice. I also commented out get_search_form in the sidebar yet when I refresh my page, it's still there. I am using the filter incorrectly? My search function is in the functions.php.

share|improve this question
up vote 0 down vote accepted

Your syntax is wrong, you're mixing up the html and php function at the beginning.

See Filter here - wp-includes/general-template.php#L151

I think we should return the form, instead of printing it, See my example, It should work, If you want to modify something, do it in function.

Example -

function savior_search(){

    //Modify This
    $form = '<form role="search" method="get" id="searchform" action="' . esc_url( 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') .'" />

    return $form;

add_filter( 'get_search_form', 'savior_search');
share|improve this answer
I see. Thank you. – Jamie Aug 19 '12 at 15:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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