image_hwstring

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

Description

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

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.

Returns (string)

HTML attributes for width and, or height.

Parameters (2)

0. $width (int|string)
Image width in pixels.
1. $height (int|string)
Image height in pixels.

Usage

  1. if ( !function_exists( 'image_hwstring' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // Image width in pixels. 
  5. $width = null; 
  6.  
  7. // Image height in pixels. 
  8. $height = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = image_hwstring($width, $height); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/media.php  
  1. function image_hwstring( $width, $height ) { 
  2. $out = ''; 
  3. if ($width) 
  4. $out .= 'width="'.intval($width).'" '; 
  5. if ($height) 
  6. $out .= 'height="'.intval($height).'" '; 
  7. return $out;