Make WordPress Core

Opened 13 years ago

Closed 7 years ago

#20358 closed defect (bug) (duplicate)

Filter image_hwstring()

Reported by: wpsmith's profile 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 13 years ago.

Download all attachments as: .zip

Change History (11)

#1 @wpsmith
13 years ago

  • Component changed from General to Media

#2 @nacin
13 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.

#3 @nacin
13 years ago

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

#4 @SergeyBiryukov
12 years ago

#22285 was marked as a duplicate.

#5 @SergeyBiryukov
11 years ago

  • Description modified (diff)

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


11 years ago

#7 @Cibulka
7 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Hardcoded image dimmensions, that can't be manipulated in any way - this is the biggest WTF I have with WordPress. Is there ANY reason, why image_hwstring exists? Or why it can't be filtered?

Also, why is this issue closed?

#8 @johnbillion
7 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

This is a duplicate of #14110 which has had no feedback in three years.

CSS rules for width and height override the width and height attributes on the img element.

#9 @Cibulka
7 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Thanks for the quick reply!

CSS can override this, but don't you agree it's a little bit silly to fix incorrect output with CSS? Wouldn't be easier to simply make this function filterable?

I'm not the lonely head scratcher here:

... and many, many more.

I've ended up with very complex filtering of image_downsize function: https://gist.github.com/cibulka/8e2bf16b0f55779af590472ae1bf9239

The gist of the sollution is to remove image dimmensions from image_downsize function, as it is the only way (!!!) how to influence image_hwstring.

One of many side effects of this sollutions is that wp_get_attachment_src obviously stops returning image dimmensions - so for this functionality I needed to create my own function.

Wouldn't is just be easier to make a filter? :)

Last edited 7 years ago by Cibulka (previous) (diff)

#10 @dd32
7 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

I'm going to re-close this as a duplicate of #14110.

If you feel strongly about having it filtered, please re-open that main ticket, as it's where all discussion has been re-routedd to.

Please don't re-open this ticket because you want a filter, please take it to #14110.

Note: See TracTickets for help on using tickets.