function add_alt_text_column($columns) {
$columns['alt_text'] = 'Alt Text';
return $columns;
}
add_filter('manage_media_columns', 'add_alt_text_column');
// Display alt text with colored dot in the custom column
function display_alt_text_column($column_name, $attachment_id) {
if ($column_name === 'alt_text') {
$alt_text = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$file_type = wp_check_filetype(wp_get_attachment_url($attachment_id));
$image_types = array('jpg', 'jpeg', 'png', 'webp', 'avif', 'gif', 'svg');
if (in_array($file_type['ext'], $image_types)) {
if (!empty($alt_text)) {
echo esc_html($alt_text);
} else {
echo '<div style="display:flex;align-items:center;"><p style="margin:0;color: red;font-size: 48px;">•</p><p style="margin-top:1.1rem;padding-left:1rem;font-weight:700;">Missing Alt text!</p></div>';
}
} else {
echo '<div style="display:flex;align-items:center;"><p style="margin:0;color: royalblue;font-size: 48px;">•</p><p style="margin-top:1.1rem;padding-left:1rem;font-weight:700;">N/A</p></div>';
}
}
}
add_action('manage_media_custom_column', 'display_alt_text_column', 10, 2);