12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Oct 1, 2019

How to change Screen Reader Text in WordPress Search Form

Sridhar Katakam

HTML5 output of search form in WordPress has Search for: screen reader text.

<label class="screen-reader-text" for="s">Search for:</label>

If you want to change this text, add the following as a Code Snippet or in theme’s functions.php/functionality plugin’s main php file:

add_filter( 'gettext_with_context', 'wpdd_change_search_screen_reader_text', 10, 4 );
/**
 * Change screen reader text in search form.
 * 
 * @param  string $translated Translated text
 * @param  string $text       Text to translate
 * @param  string $context    Context information for the translators
 * @param  string $domain     Domain to retrieve the translated text
 * @return string             Modified translated text
 * 
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function wpdd_change_search_screen_reader_text( $translated, $text, $context, $domain ) {

	if ( 'Search for:' === $text && 'label' === $context ) {
		$translated = __( 'Do a search for:', 'text_domain' );
	}

	return $translated;
}

Change Do a search for: in the above to your desired replacement text.

Reference

https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext_with_context

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right