image_hwstring

The timeline below displays how wordpress function image_hwstring has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * 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.
 *
 * @since 2.5.0
 *
 * @param int|string $width  Image width in pixels.
 * @param int|string $height Image height in pixels.
 * @return string HTML attributes for width and, or height.
 */
function image_hwstring($width, $height)
{
    $out = '';
    if ($width) {
        $out .= 'width="' . (int) $width . '" ';
    }
    if ($height) {
        $out .= 'height="' . (int) $height . '" ';
    }
    return $out;
}

WordPress Version: 5.6

/**
 * Retrieve 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.
 *
 * @since 2.5.0
 *
 * @param int|string $width  Image width in pixels.
 * @param int|string $height Image height in pixels.
 * @return string HTML attributes for width and, or height.
 */
function image_hwstring($width, $height)
{
    $out = '';
    if ($width) {
        $out .= 'width="' . (int) $width . '" ';
    }
    if ($height) {
        $out .= 'height="' . (int) $height . '" ';
    }
    return $out;
}

WordPress Version: 4.2

/**
 * Retrieve 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.
 *
 * @since 2.5.0
 *
 * @param int|string $width  Image width in pixels.
 * @param int|string $height Image height in pixels.
 * @return string HTML attributes for width and, or height.
 */
function image_hwstring($width, $height)
{
    $out = '';
    if ($width) {
        $out .= 'width="' . intval($width) . '" ';
    }
    if ($height) {
        $out .= 'height="' . intval($height) . '" ';
    }
    return $out;
}

WordPress Version: 3.7

/**
 * Retrieve 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.
 *
 * @since 2.5.0
 *
 * @param int|string $width Optional. Width attribute value.
 * @param int|string $height Optional. Height attribute value.
 * @return string HTML attributes for width and, or height.
 */
function image_hwstring($width, $height)
{
    $out = '';
    if ($width) {
        $out .= 'width="' . intval($width) . '" ';
    }
    if ($height) {
        $out .= 'height="' . intval($height) . '" ';
    }
    return $out;
}