Opened 10 months ago
Closed 10 months ago
#64405 closed defect (bug) (duplicate)
svg icons not showing in the media library in list view
| Reported by: | mmjaeger | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: | administration |
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
@
10 months ago
- Keywords needs-patch removed
- Milestone Awaiting Review
- Resolution → duplicate
- Status new → closed
- Version 6.9
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
This was also reported 11 years ago: #26256.
Official SVG uploads support is being tracked in #24251.