WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 17 months ago

#20358 closed defect (bug) (duplicate)

Filter image_hwstring()

Reported by: wpsmith Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Make it possible to remove width and height from media HTML output functions by filtering image_hwstring(). This is perfect for responsiveness.

This can be done a few different ways:

function image_hwstring($width, $height) {
	$out = '';
	if ($width)
		$out .= 'width="'.intval($width).'" ';
	if ($height)
		$out .= 'height="'.intval($height).'" ';
	return apply_filters( 'image_hwstring', $out );
}

This could be easily filtered by something like:

add_filter( 'image_hwstring', '__return_empty_string' );

See #20357.

Attachments (1)

image_hwstring_filter.patch (1.0 KB) - added by wpsmith 3 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 @wpsmith3 years ago

  • Component changed from General to Media

comment:2 @nacin3 years ago

I think image_hwstring() is too low level for this, as it is but a helper.

Instead, we should push 'height' and 'width' into the attributes in wp_get_attachment_image(), which will force them through the wp_get_attachment_image_attributes filter. There is a duplicate ticket covering thid.

comment:3 @nacin3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

comment:4 @SergeyBiryukov3 years ago

#22285 was marked as a duplicate.

comment:5 @SergeyBiryukov17 months ago

  • Description modified (diff)

comment:6 @ircbot17 months ago

This ticket was mentioned in IRC in #wordpress-dev by SergeyBiryukov. View the logs.

Note: See TracTickets for help on using tickets.