[wp-trac] [WordPress Trac] #48149: Suggestion: Optional parameter to remove width and height attribute from attachment image markup

WordPress Trac noreply at wordpress.org
Thu Sep 26 10:20:27 UTC 2019


#48149: Suggestion: Optional parameter to remove width and height attribute from
attachment image markup
------------------------------+-----------------------------------
 Reporter:  subrataemfluence  |      Owner:  (none)
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Media             |    Version:  5.2.3
 Severity:  normal            |   Keywords:  has-patch 2nd-opinion
  Focuses:                    |
------------------------------+-----------------------------------
 First of all I am sorry if this had already been addressed and enhanced.
 I am on 5.2.3.

 Like `post_thumbnail_html` and `image_send_to_editor` filters I was unable
 to find one for attachment images for posts.

 If we can add an additional Boolean type argument in
 `wp_get_attachment_image` function (`/wp-includes/media.php`, line 872) in
 the following manner and create `$hwstring` string based on this
 argument's value, it will give us the control to decide whether or not to
 render those two attributes.

 Here is my suggestion:

 {{{#!php
 <?php
 function wp_get_attachment_image( $attachment_id, $size = 'thumbnail',
 $render_hw = false, $icon = false, $attr = '' ) {
      ...
      $hwstring = $render_hw ? image_hwstring( $width, $height ) : '';
      ...
 }
 }}}

 The default function call will be:

 {{{
 wp_get_attachment_image( $att->ID,  'infotravel-post-page-thumb' );
 }}}

 And, if `width` and `height` attributes need to be added, the function
 call will change to:


 {{{
 wp_get_attachment_image( $att->ID, true,  'infotravel-post-page-thumb' );
 }}}


 There are two reasons why I am proposing this:
 1. Responsiveness. Image width is controlled from CSS and media-queries
 2. The function already accepts a `$size`. Since we have the ability to
 pass a specific known size, we do not need to add width and height
 attributes.

 Based on the above approach I have proposed a patch. Please let me know
 whether it is useful!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48149>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list