Skip to content

Instantly share code, notes, and snippets.

@joshuafredrickson
Created October 31, 2025 16:41
Show Gist options
  • Select an option

  • Save joshuafredrickson/e4b855256b739a0e568b4dd8f4c3148e to your computer and use it in GitHub Desktop.

Select an option

Save joshuafredrickson/e4b855256b739a0e568b4dd8f4c3148e to your computer and use it in GitHub Desktop.
Add Alt Text and Dimensions columns to the Media Library
/**
* Add alt text and dimensions columns to the media library
*/
add_filter('manage_media_columns', function (array $columns): array {
$columns['alt'] = 'Alt Text';
$columns['dimensions'] = 'Dimensions';
return $columns;
});
/**
* Display alt text and dimensions in the media library
*/
add_action('manage_media_custom_column', function (string $column_name, int $id): void {
if ($column_name === 'dimensions') {
$image = wp_get_attachment_metadata($id);
echo $image['width'] . ' x ' . $image['height'];
} elseif ($column_name === 'alt') {
$alt = get_post_meta($id, '_wp_attachment_image_alt', true);
echo $alt ?: '⚠️ No alt text';
}
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment