[wp-trac] [WordPress Trac] #63714: Missing width/height attributes on SVG file since WP 6.8.2

WordPress Trac noreply at wordpress.org
Fri Jul 25 02:16:03 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:  has-patch has-unit-tests needs-testing  |     Focuses:
----------------------------------------------------+---------------------

Comment (by rollybueno):

 == 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_attributes`
 filter, use this on your theme functions.php
 {{{
 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 );
 }}}
 - 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 `2015`
 theme, 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()`
 [[Image(https://i.imgur.com/XkWWbmB.png)]]

 **Test unit**:
 [[Image(https://i.imgur.com/HJIKtaS.png)]]

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63714#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list