Show the Number of Search Results
Prints a line such as 12 results for "pricing" above the search results, so visitors know how much was found.
Opens WPIDE on
Code
add_action( 'loop_start', function ( $query ) {
static $done = false;
if ( $done || ! $query->is_main_query() || ! $query->is_search() ) {
return;
}
$done = true;
$count = (int) $query->found_posts;
$label = 1 === $count ? '%1$s result for "%2$s"' : '%1$s results for "%2$s"';
echo '<p class="wpide-search-count">' . esc_html( sprintf( $label, number_format_i18n( $count ), get_search_query( false ) ) ) . '</p>';
} );
Notes
The line appears where your theme starts the results loop.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.