#63714 closed defect (bug) (fixed)
Missing width/height attributes on SVG file since WP 6.8.2
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | 6.8.2 |
| Component: | Media | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
The latest release of WP (6.8.2) removes all the width and height attributes on SVG files causing massive design issues.
See attachment.
Downgrading to 6.8.1 solves the bug.
Attachments (2)
Change History (43)
#1
follow-up:
↓ 5
@
4 months ago
Code used:
wp_get_attachment_image($image, $size, '', array('class' => 'mb-4', 'height' => 60, 'width' => 60));
#2
@
4 months ago
- Component changed from General to Media
Hello @rainbowgeek, welcome to WordPress Trac!
Thanks for the report. The only related change seems to be [60415]. Do you mabye have a plugin active which changes the attributes via the wp_get_attachment_image_attributes filter?
#3
@
4 months ago
We confirm that no plugins, themes, or must-use plugins are using the wp_get_attachment_image_attributes hook.
#5
in reply to:
↑ 1
@
4 months ago
First look, I don't think $attr supports 'height' & 'width' as per https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
Though the doc could be outdated.. will try to reproduce later.
Replying to rainbowgeek:
Code used:
wp_get_attachment_image($image, $size, '', array('class' => 'mb-4', 'height' => 60, 'width' => 60));
#6
@
4 months ago
Reproduction Report
Description
This report validates whether the issue can be reproduced.
Environment
- WordPress: 6.8.1
- PHP: 8.2.27
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.2.27)
- Browser: Chrome 137.0.0.0
- OS: Linux
- Theme: Twenty Fifteen 4.0
- MU Plugins: None activated
- Plugins:
- Safe SVG 2.3.1
- Test Reports 1.2.0
Actual Results
- ❎ Cannot reproduce.
I came to this conclusion since the report stated that the code used wp_get_attachment_image($image, $size, '', array('class' => 'mb-4', 'height' => 60, 'width' => 60)); is working on WP v6.8.1.
After using the same code with correct SVG attachment ID and empty size parameters, the wp_get_attachment_image() ignores the height & width in the $attr params even in 6.8.1.
Additional Notes
- Downgraded to 6.8.1
- Uses 2015 theme with only 2 plugins active
- There's no additional filter manipulation, only the code provided
- Uses same code provided by reporter
echo wp_get_attachment_image( 8, '', '', array( 'class' => 'mb-4', 'height' => 60, 'width' => 60 ) ); - The only difference are the 1st & 2nd parameters which are ID and size.
- The WebP version ignores the height & width value but returns srcset for smaller device compatibility.
- The SVG ignores the
heightandwidth
❗❗❗ The only time I was able to change the height and width value through wp_get_attachment_image() is when using array( 60, 60 ) in the $size param, but it only works on normal images and not SVG.
Code used: 
❗❗❗We need more tester to try reproducing
Supplemental Artifacts
6.8.1
#7
follow-up:
↓ 10
@
4 months ago
Use this code to allow SVG in a mu-plugin (not Safe SVG plugin):
function wp_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'wp_mime_types');
Then upload a SVG file to the media library, pass the attachment ID to the $image variable:
wp_get_attachment_image(1, 'full', '', array('class' => 'mb-4', 'height' => 60, 'width' => 60));
Echo it in your theme somewhere (eg: functions.php with the code below).
add_action('wp_head', function() {
echo wp_get_attachment_image(7, 'full', '', array('class' => 'mb-4', 'height' => 60, 'width' => 60));
});
Result with WP 6.8.2:
<img src="http://test.local/wp-content/uploads/2025/07/ico-newsletter.svg" class="mb-4" alt="" decoding="async" loading="lazy">
Result with WP 6.8.1:
<img src="http://test.local/wp-content/uploads/2025/07/ico-newsletter.svg" class="mb-4" alt="" height="60" width="60" decoding="async" loading="lazy">
#8
@
4 months ago
I was able to reproduce the bug following the steps mentioned by @rainbowgeek
Reproduction Report
Description
This report validates whether the issue can be reproduced.
Environment
- WordPress: 6.8.1, 6.8.2
- PHP: 8.2.23
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.2.23)
- Browser: Chrome 138.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.0
- MU Plugins:
- test 1 (contains code to allow SVG)
- Plugins:
- Test Reports 1.2.0
Actual Results
- ✅ Error condition occurs (reproduced).
Steps for reproduction
- Add a mu-plugin with the following code:
<?php add_filter('upload_mimes', function($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; });
- Go to the Media Library and upload an SVG file. Note its attachment ID.
- In your theme’s
functions.php, add:
<?php add_action('wp_head', function() { echo wp_get_attachment_image(ATTACHMENT_ID, 'full', '', array( 'class' => 'mb-4', 'height' => 240, 'width' => 240 )); });
Replace
ATTACHMENT_IDwith the actual SVG attachment ID.
- Visit the frontend and inspect the rendered
<img>tag in the browser. - Check for both WP 6.8.1 and WP 6.8.2
Additional Notes
- Height and width attributes show up on using WP 6.8.1
- Height and width attributes do not show up on using WP 6.8.2
- The same code was used to add SVG for both WP versions
Supplemental Artifacts
#9
@
4 months ago
We had same issue in some of the sites we're trying to update today. Still trying to see if we can find a way to work around this, meaning to get the width and height attributes back on SVG logos without rolling back to WordPress 6.8.1.
We're rendering the SVG images with wp_get_attachment_image() call.
echo wp_get_attachment_image( $logo, 'logo-235x40', false, array( 'alt' => esc_attr( get_bloginfo( 'name' ) . ' - ' . get_bloginfo( 'description' ) ), 'height' => '40', 'width' => '235', ) );
#10
in reply to:
↑ 7
@
4 months ago
- Keywords needs-patch added
Thank you! This filter upload_mimes is the missing piece to reproduce, and I was able to do that after adding that filter.
function wp_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'wp_mime_types');
Replying to rainbowgeek:
Use this code to allow SVG in a mu-plugin (not Safe SVG plugin):
function wp_mime_types($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'wp_mime_types');Then upload a SVG file to the media library, pass the attachment ID to the $image variable:
wp_get_attachment_image(1, 'full', '', array('class' => 'mb-4', 'height' => 60, 'width' => 60));Echo it in your theme somewhere (eg: functions.php with the code below).
add_action('wp_head', function() { echo wp_get_attachment_image(7, 'full', '', array('class' => 'mb-4', 'height' => 60, 'width' => 60)); });Result with WP 6.8.2:
<img src="http://test.local/wp-content/uploads/2025/07/ico-newsletter.svg" class="mb-4" alt="" decoding="async" loading="lazy">Result with WP 6.8.1:
<img src="http://test.local/wp-content/uploads/2025/07/ico-newsletter.svg" class="mb-4" alt="" height="60" width="60" decoding="async" loading="lazy">
#11
@
4 months ago
- Keywords 2nd-opinion dev-feedback added
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 );
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 );
Adding 2nd-opinion tag to get more opinions if we should:
- Keep the current version & control the height & width through
wp_get_attachment_image_srcfilter or - Introduce a backward compatibility..
This ticket was mentioned in PR #9315 on WordPress/wordpress-develop by @heybran.
4 months ago
#13
- Keywords has-patch has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/63714
#14
in reply to:
↑ 12
;
follow-up:
↓ 17
@
4 months ago
Replying to rollybueno:
Hi Rolly,
I noticed that you've removed the needs-patch keyword, does it mean this ticket is not ready for a PR/patch? I just submitted a PR to fix the issue reported in this ticket. First time contributing codes, so please forgive me if this question is a bit stupid.
@mukesh27 commented on PR #9315:
4 months ago
#15
Thanks @heybran for the PR.
I’ve left some feedback and suggestions. Please take a look and let me know if you need any clarification or further details.
@mukesh27 commented on PR #9315:
4 months ago
#16
@adamsilverstein Could you please take a look when you have time?
#17
in reply to:
↑ 14
@
4 months ago
- Keywords needs-testing added; 2nd-opinion dev-feedback removed
Hey @heybran, no not at all. The reason I removed that is for further discussions with the maintainer, but since you already push a PR, let's go ahead. Mukesh already left some review, which is great.
Replying to heybran:
Replying to rollybueno:
Hi Rolly,
I noticed that you've removed the
needs-patchkeyword, does it mean this ticket is not ready for a PR/patch? I just submitted a PR to fix the issue reported in this ticket. First time contributing codes, so please forgive me if this question is a bit stupid.
#18
@
4 months ago
Test Report
Description
This report validates whether the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/9315
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.29.0
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 137.0.0.0
- OS: Linux
- Theme: Twenty Fifteen 4.0
- MU Plugins: None activated
- Plugins:
- Query Monitor 3.18.0
- Test Reports 1.2.0
Actual Results
✅ - Tested using defined width and height on attr params in wp_get_attachment_image.
✅ - Tested without width and height on attr params in wp_get_attachment_image. It uses the attachment height and width by default. No regressions found.
✅ - Tested setting width and height through wp_get_attachment_image_attributes filter. Confirming that the enhancement on https://core.trac.wordpress.org/ticket/14110 will not regress.
✅ - Tested setting width and height through wp_get_attachment_image_attributes filter and through attr params in wp_get_attachment_image to see which one will be prioritised. Height and width values are coming from wp_get_attachment_image_attributes filter, which is correct since it comes late in heirarchy. No regressions found.
✅ Issue resolved with patch.
Additional Notes
- To pull the PR, follow these steps:
git fetch upstream pull/9315/head:pr-9315 git checkout pr-9315
- Add the following filter on your theme's functions.php
add_filter( 'upload_mimes', function ( $mimes ) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } ); - To set the widht and height through
wp_get_attachment_image_attributesfilter, use this on your theme functions.phpfunction 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 ); - To run the test unit:
npm run test:php -- --filter test_wp_get_attachment_image_not_overwrite_user_provided_width_height
- Use the following code, which I put in the content.php using
2015theme, where 70 is the SVG attachment ID in my local. Replace that based in your SVG attachment ID in your local env:echo wp_get_attachment_image( 70, 'full', '', array( 'class' => 'mb-4', 'height' => 60, 'width' => 60 ) );
Supplemental Artifacts
See the before and reproduced information on https://core.trac.wordpress.org/ticket/63714#comment:11
After pulling the patch and restarting the env:
This now respecting the user defined height and width when using wp_get_attachment_image()

#19
@
4 months ago
So far, the patch from @heybran is okay. I'll leave the needs-testing open a bit for at least 1 more result from other tester, and we wait for Component Maintainer to review and approve.
cc @adamsilverstein
#20
@
4 months ago
- Owner set to adamsilverstein
- Status changed from new to assigned
Thanks for ticket and the ping, I will take a look!
@adamsilverstein commented on PR #9315:
4 months ago
#21
Looks good to me - thanks for the PR @heybran and the review @mukeshpanchal27!
#22
@
4 months ago
PR looks good, thanks everyone for the fix here. I want to look a bit further to understand why this only breaks for SVGs but will plan get this committed for 6.8.3.
This ticket was mentioned in Slack in #core-test by oglekler. View the logs.
3 months ago
This ticket was mentioned in Slack in #core-test by rollybueno. View the logs.
3 months ago
This ticket was mentioned in Slack in #core-test by sirlouen. View the logs.
3 months ago
#30
@
3 months ago
- Keywords needs-test-info added
Reproduction Report
Description
This report validates whether the issue can be reproduced.
Environment
- WordPress: 6.8.1-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 138.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.2
- MU Plugins:
- allow-svg.php
- Plugins:
- Test Reports 1.2.0
Actual Results
- Unable to reproduce the issue.
Reproduction Steps
- Used this code to allow SVG in a mu-plugin
<?php function wp_mime_types($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'wp_mime_types');
- Then I uploaded the SVG file to the media library
- In the theme’s functions.php, I added this code with the correct attachment I'd
<?php add_action('wp_head', function() { echo wp_get_attachment_image(15, 'full', '', array('class' => 'mb-4', 'height' => 60, 'width' => 60)); });
- Then i checked for both WP 6.8.1 and WP 6.8.2, but I cannot find the height and width attributes in any. I got everything same in both versions.
Additional Notes
- This is what I did, if I'm doing something wrong, can you review my steps and tell me what I'm missing?"
This ticket was mentioned in Slack in #core-test by iamshashank. View the logs.
3 months ago
#32
@
3 months ago
- Keywords needs-test-info removed
I figured out what was wrong while reproducing it, I had been inspecting the SVG after adding it to a page via the media library, and everything looked fine there. But when I checked the SVG on the homepage, that’s where the problem appeared. Now i'm able to reproduce the issue.
#33
@
3 months ago
Test Report
Description
✅ This report validates that the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/9315.diff
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 138.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.3
- MU Plugins:
- allow-svg.php
- Plugins:
- Test Reports 1.2.0
Actual Results
- ✅ Issue resolved with patch.
Additional Notes
- I was able to test this patch on WP version 6.9-alpha-60093-src, but when I tried the same patch on version 6.8.2, I got:
1 out of 1 hunks failed--saving rejects to 'src/wp-includes/media.php.rej'
Screenshots
#36
@
3 months ago
- Severity changed from major to normal
This is fixed in trunk (6.9). Reopening for consideration of back porting to 6.8.3.
#38
@
6 weeks ago
- Milestone changed from 6.8.3 to 6.8.4
6.8.3 was a security only release. Punting though 6.8.4 is not planned as a release
#39
@
6 days ago
Thanks everyone for your contributions on this ticket. Just noting that the fix is in trunk, meaning it will become available to everyone in a few weeks with the release of WordPress 6.9.
I will leave this open in case we want to ship the fix for the 6.8 branch as well.
#40
@
10 hours ago
- Keywords commit removed
- Milestone changed from 6.8.4 to 6.9
- Resolution set to fixed
- Status changed from reopened to closed
With 6.9 RC1 out, there are no plans to ship a 6.8.4 release. Moving this to the 6.9 milestone as that will be the first release containing the changes from this ticket.














WP 6.8.1 with attributes