# Images Missing Alt Text Dashboard Widget

> Adds a dashboard widget showing how many images in the Media Library have no alternative text, with a link to the most recent ones to fix.

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

## Code

```php
$wpide_alt_count = function () {
    global $wpdb;

    $count = get_transient( 'wpide_missing_alt_count' );

    if ( false === $count ) {
        $count = (int) $wpdb->get_var(
            "SELECT COUNT(p.ID) FROM {$wpdb->posts} p
             LEFT JOIN {$wpdb->postmeta} m ON m.post_id = p.ID AND m.meta_key = '_wp_attachment_image_alt'
             WHERE p.post_type = 'attachment' AND p.post_mime_type LIKE 'image/%' AND ( m.meta_value IS NULL OR m.meta_value = '' )"
        );
        set_transient( 'wpide_missing_alt_count', $count, 12 * HOUR_IN_SECONDS );
    }

    return (int) $count;
};

$wpide_alt_flush = function ( $meta_id, $object_id, $meta_key ) {
    if ( '_wp_attachment_image_alt' === $meta_key ) {
        delete_transient( 'wpide_missing_alt_count' );
    }
};
add_action( 'added_post_meta', $wpide_alt_flush, 10, 3 );
add_action( 'updated_post_meta', $wpide_alt_flush, 10, 3 );
add_action( 'add_attachment', function () {
    delete_transient( 'wpide_missing_alt_count' );
} );

add_action( 'wp_dashboard_setup', function () use ( $wpide_alt_count ) {
    if ( ! current_user_can( 'upload_files' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_missing_alt', 'Images Missing Alt Text', function () use ( $wpide_alt_count ) {
        $count = $wpide_alt_count();

        if ( ! $count ) {
            echo '<p>Every image has alternative text. Nice work.</p>';
            return;
        }

        $recent = get_posts( array(
            'post_type'      => 'attachment',
            'post_mime_type' => 'image',
            'post_status'    => 'inherit',
            'posts_per_page' => 5,
            'no_found_rows'  => true,
            'meta_query'     => array(
                'relation' => 'OR',
                array( 'key' => '_wp_attachment_image_alt', 'compare' => 'NOT EXISTS' ),
                array( 'key' => '_wp_attachment_image_alt', 'value' => '' ),
            ),
        ) );

        printf( '<p><strong>%s</strong> image(s) have no alt text. Most recent:</p><ul>', esc_html( number_format_i18n( $count ) ) );
        foreach ( $recent as $image ) {
            printf( '<li><a href="%s">%s</a></li>', esc_url( get_edit_post_link( $image->ID ) ), esc_html( $image->post_title ? $image->post_title : '#' . $image->ID ) );
        }
        echo '</ul>';
    } );
} );
```

## Notes

The count is cached for 12 hours and refreshed whenever an image's alt text changes.

## How to use it

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