How to Change the Placeholder text for the WordPress Search Form

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 functions.php in your WordPress theme and we are all set. The placeholder text can be changed/replaced with any text. Also, the search button can be changed to anything. It’s pretty customisable using the below function.


/**
 *  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' );

We hope this article has helped you to be able to change the placeholder text for the WordPress search box.

Are you wanting to customise the default WordPress Search?

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.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development and web site design. His expertise is WordPress & Magento as well as many other frameworks. Would you like to work with Nathan? Send him an email on [email protected]

It’s good to share