image_hwstring()WP 2.5.0

Retrieves width and height attributes using given width and height values.

Both attributes are required in the sense that both parameters must have a value, but are optional in that if you set them to false or null, then they will not be added to the returned string.

You can set the value using a string, but it will only take numeric values. If you wish to put 'px' after the numbers, then it will be stripped out of the return.

No Hooks.

Return

String. HTML attributes for width and, or height.

Usage

image_hwstring( $width, $height );
$width(int|string) (required)
Image width in pixels.
$height(int|string) (required)
Image height in pixels.

Changelog

Since 2.5.0 Introduced.

image_hwstring() code WP 6.5.2

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