Search Results Heading

Use this for the “Showing 1-10 of 20 results” text above the listing.

/**
 * Search Heading
 * @link https://www.billerickson.net/code/search-results-heading/
 */
function ea_search_results_heading() {
	global $wp_query;
	$paged = get_query_var( 'paged') ? get_query_var( 'paged' ) : 1;
	$per_page = get_query_var( 'posts_per_page' );
	$start = 1 + $per_page * ( $paged - 1 );
	$end = $start + $per_page - 1 > $wp_query->found_posts ? $wp_query->found_posts : $start + $per_page - 1;
	$output = 'Showing ' . $start . '-' . $end . ' of ' . $wp_query->found_posts . ' results';
	echo '<div class="search-count">' . $output . '</div>';
}

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk