Skip to content

Instantly share code, notes, and snippets.

@scottnunemacher
Last active March 6, 2023 16:09
Show Gist options
  • Save scottnunemacher/80cef7c1de9402236d6a02c359f510f2 to your computer and use it in GitHub Desktop.
Save scottnunemacher/80cef7c1de9402236d6a02c359f510f2 to your computer and use it in GitHub Desktop.
Custom Search Results Subheading
<?php
// Custom Search Results Subheading
add_filter( 'custom_search_results_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;
} );
?>
//Use:
<?php global $wp_query; echo $wp_query->found_posts.' results found.'; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment