Steps
-
Add the PHP code to your theme’s
functions.phpfile or a PHP snippets plugin. -
Save and activate the snippet.
-
Search for any keyword on your website.
-
The result count will appear before the search results loop.
/**
* Display the number of search results
*/
function custom_display_search_result_count() {
if ( ! is_search() ) {
return;
}
global $wp_query;
$count = (int) $wp_query->found_posts;
echo '<div class="search-result-count">';
if ( $count > 0 ) {
echo esc_html( number_format_i18n( $count ) ) . ' results found.';
} else {
echo 'No results found.';
}
echo '</div>';
}
add_action( 'loop_start', 'custom_display_search_result_count' );
Tested on
WordPress 6.8
Reported by the author on November 16, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.5. It may still work.
