[wp-trac] [WordPress Trac] #64405: svg icons not showing in the media library in list view
WordPress Trac
noreply at wordpress.org
Fri Dec 12 00:31:39 UTC 2025
#64405: svg icons not showing in the media library in list view
----------------------------+-----------------------------
Reporter: mmjaeger | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 6.9
Severity: normal | Keywords: needs-patch
Focuses: administration |
----------------------------+-----------------------------
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
<?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);}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64405>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list