Add an "Alt text" column to the Media Library list that flags images with no alt text, and a filter to show only those.
add_filter( 'manage_media_columns', function ( array $columns ): array {
$columns['nahnu_alt'] = 'Alt text';
return $columns;
} );
add_action( 'manage_media_custom_column', function ( string $column, int $post_id ): void {
if ( 'nahnu_alt' !== $column || ! wp_attachment_is_image( $post_id ) ) {
return;
}
$alt = trim( (string) get_post_meta( $post_id, '_wp_attachment_image_alt', true ) );
echo '' === $alt ? '<span style="color:#b32d2e">Missing</span>' : esc_html( wp_trim_words( $alt, 8 ) );
}, 10, 2 );
// Add ?nahnu_missing_alt=1 to the Media list URL to show only images without alt text.
add_action( 'pre_get_posts', function ( WP_Query $query ): void {
global $pagenow;
if ( ! is_admin() || 'upload.php' !== $pagenow || ! $query->is_main_query() || empty( $_GET['nahnu_missing_alt'] ) ) {
return;
}
$query->set( 'post_mime_type', 'image' );
$query->set( 'meta_query', [
'relation' => 'OR',
[ 'key' => '_wp_attachment_image_alt', 'compare' => 'NOT EXISTS' ],
[ 'key' => '_wp_attachment_image_alt', 'value' => '' ],
] );
} );
add_action( 'restrict_manage_posts', function ( string $post_type ): void {
if ( 'attachment' === $post_type ) {
printf( '<a class="button" href="%s">Missing alt text</a> ', esc_url( admin_url( 'upload.php?mode=list&nahnu_missing_alt=1' ) ) );
}
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Alt text describes images for people using screen readers, and helps search engines too. It’s easy to forget, and the Media Library gives no way to find the gaps. This snippet adds a column and a one-click filter.
manage_media_columns adds the column, which shows the start of each image’s alt text, or “Missing” in red.
The “Missing alt text” button adds nahnu_missing_alt=1 to the URL. pre_get_posts then limits the list to images whose _wp_attachment_image_alt meta is empty or doesn’t exist.
Go to Media → Library in list view and click “Missing alt text”. Only images without alt text should be listed.