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

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

Description 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 Parameters


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


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

Top ↑

Return Return

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

Top ↑

Source Source

File: wp-includes/media.php

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

Top ↑

Changelog Changelog

Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.