Skip to content

Snippet: Add Search Results Count to Search Results Page

Important: You can now use the theme's "post_count" dynamic variable to display this data when creating dynamic templates for your archives!

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( 'totaltheme/page/header/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' ),
				get_search_query( false )
	return $subheading;
} );
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