Snippets: Add Search Results Count to Search Results Page

The following snippet will add a subheading to the search results page (subheadings display under the main title in side the page header title area) in the following format: "Displaying results 1-10 out of 573 for {{query}}".

// Custom search results subheading
add_filter( 'wpex_post_subheading', function( $subheading ) {
	if ( is_search() ) {
		global $wp_query;
		$posts_per_page = $wp_query->query_vars['posts_per_page'];
		$posts_found    = $wp_query->found_posts;
		if ( $posts_found ) {
			$subheading = sprintf(
				esc_html__( 'Displaying results 1-%1$s out of %2$s for %3$s', 'total' ),
				$posts_per_page,
				$posts_found,
				get_search_query( false )
			);
		}
	}
	return $subheading;
} );

Result:

Snippet Type: PHP

All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)