# Announce the Number of Search Results

> On search result pages, tells screen reader users how many results were found for their search as soon as the page loads.

- Type: PHP
- Runs: Frontend cl
- Category: [Accessibility](https://wpide.com/library/category/accessibility/)
- Tags: search, screen-reader, aria-live
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/a11y-announce-search-results/

## Code

```php
add_action( 'wp_footer', function () {
    if ( ! is_search() ) {
        return;
    }

    global $wp_query;
    $count   = (int) $wp_query->found_posts;
    $message = $count
        ? sprintf( _n( '%1$s result found for "%2$s".', '%1$s results found for "%2$s".', $count ), number_format_i18n( $count ), get_search_query( false ) )
        : sprintf( 'No results found for "%s".', get_search_query( false ) );

    printf(
        '<div id="wpide-search-status" class="screen-reader-text" role="status" aria-live="polite" style="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);"></div><script>setTimeout(function(){var s=document.getElementById("wpide-search-status");if(s){s.textContent=%s;}},400);</script>',
        wp_json_encode( $message )
    );
} );
```

## Notes

The message is read from a visually hidden live region; sighted visitors see no change.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Announce the Number of Search Results" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
