# "Missing Alt Text" Filter in the Media Library

> Adds a dropdown to the Media Library list view that shows only images without alternative text, so you can fix them one by one.

- Type: PHP
- Runs: Admin only
- Category: [Accessibility](https://wpide.com/library/category/accessibility/)
- Tags: alt-text, media-library, admin
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/a11y-media-filter-missing-alt/

## Code

```php
add_action( 'restrict_manage_posts', function ( $post_type ) {
    if ( 'attachment' !== $post_type ) {
        return;
    }

    $current = isset( $_GET['wpide_alt'] ) ? sanitize_key( wp_unslash( $_GET['wpide_alt'] ) ) : '';

    echo '<label class="screen-reader-text" for="wpide-alt-filter">Filter by alt text</label>';
    echo '<select name="wpide_alt" id="wpide-alt-filter">';
    echo '<option value="">All alt text states</option>';
    echo '<option value="missing"' . selected( $current, 'missing', false ) . '>Missing alt text</option>';
    echo '</select>';
} );

add_action( 'pre_get_posts', function ( $query ) {
    if ( ! is_admin() || ! $query->is_main_query() || empty( $_GET['wpide_alt'] ) || 'missing' !== $_GET['wpide_alt'] ) {
        return;
    }

    if ( 'attachment' !== $query->get( 'post_type' ) ) {
        return;
    }

    $query->set( 'post_mime_type', 'image' );
    $query->set( 'meta_query', array(
        'relation' => 'OR',
        array( 'key' => '_wp_attachment_image_alt', 'compare' => 'NOT EXISTS' ),
        array( 'key' => '_wp_attachment_image_alt', 'value' => '' ),
    ) );
} );
```

## Notes

Works in the list view of the Media Library (upload.php?mode=list).

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Missing Alt Text" Filter in the Media Library" 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/
