Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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" />
</form>
<?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

1 Answer 1

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') .'" />
                </div>
            </form>'; 

    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

 
discard

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.