Alt Text Column in the Media Library
Adds an Alt text column to the Media Library list view and flags images that have none, making accessibility clean-ups much quicker.
Opens WPIDE on
Code
add_filter( 'manage_upload_columns', function ( $columns ) {
$columns['wpide_alt'] = 'Alt text';
return $columns;
} );
add_action( 'manage_media_custom_column', function ( $column, $attachment_id ) {
if ( 'wpide_alt' !== $column || ! wp_attachment_is_image( $attachment_id ) ) {
return;
}
$alt = trim( (string) get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) );
echo '' === $alt ? '<span style="color:#d63638;font-weight:600;">Missing</span>' : esc_html( $alt );
}, 10, 2 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.