Opened 2 days ago
Closed 31 hours ago
#64405 closed defect (bug) (duplicate)
svg icons not showing in the media library in list view
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Media | Keywords: | |
| Focuses: | administration | Cc: |
Description
wordpress seems to have an issue when reading/setting the metadata for an svg file - the html for the image show height/width = 1.
the following code fixes it:
<?php // Fix WordPress 6.9 SVG dimension bug function fix_svg_dimensions($data, $id) { if (get_post_mime_type($id) === 'image/svg+xml' && (!isset($data['width']) || $data['width'] <= 1)) { $file = get_attached_file($id); if ($svg = @simplexml_load_file($file)) { $attrs = $svg->attributes(); if (isset($attrs->viewBox)) { $viewBox = preg_split('/[\s,]+/', (string)$attrs->viewBox); $data['width'] = (int)$viewBox[2]; $data['height'] = (int)$viewBox[3]; } } } return $data; } add_filter('wp_generate_attachment_metadata', 'fix_svg_dimensions', 10, 2);}}}
Change History (2)
#2
@
31 hours ago
- Keywords needs-patch removed
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
- Version 6.9 deleted
Hi and welcome to WordPress Core Trac!
The one-pixel dimensions in media list view was re-reported in #37632, and the discussion about possibly editing that view should continue there.
Note: See
TracTickets for help on using
tickets.
This was also reported 11 years ago: #26256.
Official SVG uploads support is being tracked in #24251.