WordPress search form: Customize submit button text

Actually, I just wanted to customize the text of the submit button of the standard search form. Actually. But that’s obviously not so easy, because the search form is called up with a very simple function, which, as far as I know, cannot be used to customize the text of the submit button.

Here is the standard function that can be used to place the search window anywhere in a WordPress template:

get_search_form();

There are, of course, a number of plugins that do exactly that – that offer a simple way to edit the various details of the search form – including the text of the submit button. But why install another plugin if you only want to customize the text of the submit button?

Instead, we can also relatively easily overwrite the get_search_form() function and add our own code.

/* custom search form */

function custom_search_form( $form ) {
$form = '
<section class="search"><form role="search" class="search-form" method="get" id="search-form" action="' . home_url( '/' ) . '" >
<label class="screen-reader-text" for="s">' . __( 'Search:' ) . '</label>
<input type="search" class="search-field" value="' . get_search_query() . '" name="s" id="s" placeholder="…" />
<input type="submit" class="search-submit" id="searchsubmit" value="'. esc_attr__( 'Search' ) .'" />
</form></section>
';

return $form;
}
add_filter( 'get_search_form', 'custom_search_form', 40 );

The script simply needs to be placed in the function php of the active theme – and the text of the submit button can be changed.

The code is based on the custom_search_form function, which I found under the heading ‘Custom WordPress Search Form with a Function’ at nicolaslule.com: nicolaslule.com/how-to-customize-the-search-form-in-wordpress/

There are a few more helpful tips and tricks on the page – for example, how to restrict the search to a specific post type – or how to replace the submit button with an icon.