Today we will learn how to change the placeholder text for WordPress search forms.
To display a WordPress search form you can use the following PHP code:-
<?php get_search_form(); ?>
Now, we just need to add the below code to your We hope this article has helped you to be able to change the placeholder text for the WordPress search box. You may also be wondering how you can customise the default search to only display certain things. For example, you may not want to search for posts, but only display pages or certain CPT (Custom Post Types). This can also be done bespoke, but we tend to find the Relevanssi – A Better Search plugin to do the job perfectly well, and safe quite a bit of time. Relevanssi replaces the standard WordPress search with a better search engine, with lots of features and configurable options. You'll get better results, better presentation of results and your users will thank you. If you need assistance with setting this up, feel free to get in touch, we look forward to hearing from you.functions.php
/**
* Search Form
*/
function wp_search_form( $form ) {
$form = '<section class="search search-form"><form role="search" method="get" action="' . home_url( '/' ) . '" >
<label class="screen-reader-text" for="s">' . __('', 'domain') . '</label>
<input type="search" class="search-field" value="' . get_search_query() . '" name="s" id="s" placeholder="" />
<input type="submit" id="searchsubmit" class="search-submit" value="'. esc_attr__('Go', 'domain') .'" />
</form></section>';
return $form;
}
add_filter( 'get_search_form', 'wp_search_form' );
Are you wanting to customise the default WordPress Search?