On this page
image_hwstring( int|string $width, int|string $height ): string
Retrieves 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.
Parameters
$widthint|string Required-
Image width in pixels.
$heightint|string Required-
Image height in pixels.
Return
string HTML attributes for width and, or height.
Source
File: wp-includes/media.php. View all references
function image_hwstring( $width, $height ) {
$out = '';
if ( $width ) {
$out .= 'width="' . (int) $width . '" ';
}
if ( $height ) {
$out .= 'height="' . (int) $height . '" ';
}
return $out;
}
Related
Used By
| Used By | Description |
|---|---|
| wp_img_tag_add_width_and_height_attr() wp-includes/media.php | Adds |
| get_image_tag() wp-includes/media.php | Gets an img tag for an image attachment, scaling it down if requested. |
| wp_get_attachment_image() wp-includes/media.php | Gets an HTML img element representing an image attachment. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/image_hwstring