image_hwstring() WordPress Function

image_hwstring() is a function in WordPress that allows you to output the width and height of an image as a string. This is useful for outputting images in HTML or CSS.

image_hwstring( int|string $width, int|string $height ) #

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


Description

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.


Top ↑

Parameters

$width

(int|string)(Required)Image width in pixels.

$height

(int|string)(Required)Image height in pixels.


Top ↑

Return

(string) HTML attributes for width and, or height.


Top ↑

Source

File: wp-includes/media.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More