Skip to content

Snippet: Customize Your Search Placeholder Text

By default if you are going to change the text of your search form in WordPress, we would recommend using a translation plugin such as Loco Translate. However, if you want more control or rather use code you can hook into the theme's various filters to alter the search form placeholder in various parts of the theme. Below are examples for changing the text in the default 4 sections of the site so you would copy the code for the specific form you want to change or if you want to change all of them to say the same thing you can use the last example at the bottom.

// Alter core searchform placeholder (such as sidebar widget)
add_filter( 'wpex_search_placeholder_text', function() {
    return __( 'Search our blog', 'Total' );
} );

// Alter header menu searchform placeholder text
add_filter( 'totaltheme/header/menu/search/placeholder', function() {
	return __( 'Your custom text', 'Total' );
} );

// Alter header 2 aside searchform placeholder text
add_filter( 'wpex_get_header_aside_search_form_placeholder', function() {
	return __( 'Your custom text', 'Total' );
} );

// Alter mobile menu searchform placeholder
add_filter( 'wpex_mobile_searchform_placeholder', function() {
    return __( 'Search our blog', 'Total' );
} );

/*** Example combining all 4 snippets to change the searchform everywhere ***/
function my_custom_search_placeholder_text() {
    return __( 'Your custom text', 'Total' );
}
add_filter( 'wpex_search_placeholder_text', 'my_custom_search_placeholder_text' );
add_filter( 'totaltheme/header/menu/search/placeholder', 'my_custom_search_placeholder_text' );
add_filter( 'wpex_get_header_aside_search_form_placeholder', 'my_custom_search_placeholder_text' );
add_filter( 'wpex_mobile_searchform_placeholder', 'my_custom_search_placeholder_text' );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top