[wp-trac] [WordPress Trac] #63714: Missing width/height attributes on SVG file since WP 6.8.2
WordPress Trac
noreply at wordpress.org
Tue Jul 22 15:53:46 UTC 2025
#63714: Missing width/height attributes on SVG file since WP 6.8.2
--------------------------------------------------+---------------------
Reporter: rainbowgeek | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.8.3
Component: Media | Version: 6.8.2
Severity: major | Resolution:
Keywords: needs-patch 2nd-opinion dev-feedback | Focuses:
--------------------------------------------------+---------------------
Changes (by rollybueno):
* keywords: needs-patch => needs-patch 2nd-opinion dev-feedback
Comment:
Run few more test, the point of this **regression**(not quite sure if this
should be treated as such) happens in this line:
https://core.trac.wordpress.org/browser/tags/6.8.2/src/wp-
includes/media.php#L1094 where it completely overrides the value of height
and width set when using `wp_get_attachment_image()` e.g.
{{{
wp_get_attachment_image(1, 'full', '', array('class' => 'mb-4', 'height'
=> 60, 'width' => 60));
}}}
The $width and $height is coming from the shorthand values of
`wp_get_attachment_image_src()`.
**6.8.1** set it first on temporary variable as per
https://core.trac.wordpress.org/browser/tags/6.8.1/src/wp-
includes/media.php#L1096 before using it later on, instead of overriding
those values by default.
I traced this back to this commit - https://github.com/WordPress
/wordpress-develop/commit/4014d16d222 from
https://core.trac.wordpress.org/ticket/14110, which was added just 2 weeks
ago. It basically, prioritising the width and height through
`wp_get_attachment_image_attributes` filter.
With that, I think it's either control the height & width in that filter,
or do some backward compatibility.
{{{
function test_wp_get_attachment_image_attributes( $attr, $attachment,
$size ) {
// Example: Only target SVGs
$mime = get_post_mime_type( $attachment );
if ( $mime === 'image/svg+xml' ) {
// Set custom width and height
$attr['width'] = 60;
$attr['height'] = 60;
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes',
'test_wp_get_attachment_image_attributes', 10, 3 );
}}}
**60x60**
[[Image(https://i.imgur.com/KUXLXVv.png)]]
{{{
function test_wp_get_attachment_image_attributes( $attr, $attachment,
$size ) {
// Example: Only target SVGs
$mime = get_post_mime_type( $attachment );
if ( $mime === 'image/svg+xml' ) {
// Set custom width and height
$attr['width'] = 150;
$attr['height'] = 150;
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes',
'test_wp_get_attachment_image_attributes', 10, 3 );
}}}
**150x150**
[[Image(https://i.imgur.com/goF55oH.png)]]
Adding ''2nd-opinion'' tag to get more opinions if we should:
1. Keep the current version & control the height & width through
`wp_get_attachment_image_src` filter or
2. Introduce a backward compatibility..
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63714#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list