Site logo

Archived topic

How to edit the "Search Results for"

3 replies · Started by Ika on March 16, 2021

Viewing posts 1–4 of 4

Hi guys,
Hope you and your family in good health.

When someone did a search, on top of search results would say "Search results for:....".
How do i edit this to say instead "We found x results for :....".
I really hope that it's possible to do it via code snippet coz i prefer not to have a child theme.

Pls advice.

Tq

Hi there,

Try this PHP snippet:

add_filter( 'gettext', function( $text ) {
	
	global $wp_query;
	$not_singular = $wp_query->found_posts > 1 ? 'results' : 'result'; // if found posts is greater than one echo results(plural) else echo result (singular)

	
    if ( 'Search Results for: %s' === $text ) {
        return "We found $wp_query->found_posts $not_singular for: %s";
    }
	
    return $text;
} );

Tq so much Elvin.
Work as expected.

Have a nice day and be safe.

No problem. Glad to be of any help. Be safe as well. :)

This archived topic is closed to new replies.