Title: Custom_Image_Header::get_header_dimensions
Published: April 25, 2014
Last modified: April 28, 2025

---

# Custom_Image_Header::get_header_dimensions( array $dimensions ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#wp--skip-link--target)

Calculates width and height based on what the currently selected theme supports.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#parameters)󠁿

 `$dimensions`arrayrequired

## 󠀁[Return](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#return)󠁿

 array dst_height and dst_width of header image.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#source)󠁿

    ```php
    final public function get_header_dimensions( $dimensions ) {
    	$max_width       = 0;
    	$width           = absint( $dimensions['width'] );
    	$height          = absint( $dimensions['height'] );
    	$theme_height    = get_theme_support( 'custom-header', 'height' );
    	$theme_width     = get_theme_support( 'custom-header', 'width' );
    	$has_flex_width  = current_theme_supports( 'custom-header', 'flex-width' );
    	$has_flex_height = current_theme_supports( 'custom-header', 'flex-height' );
    	$has_max_width   = current_theme_supports( 'custom-header', 'max-width' );
    	$dst             = array(
    		'dst_height' => null,
    		'dst_width'  => null,
    	);

    	// For flex, limit size of image displayed to 1500px unless theme says otherwise.
    	if ( $has_flex_width ) {
    		$max_width = 1500;
    	}

    	if ( $has_max_width ) {
    		$max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
    	}
    	$max_width = max( $max_width, $theme_width );

    	if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) {
    		$dst['dst_height'] = absint( $height * ( $max_width / $width ) );
    	} elseif ( $has_flex_height && $has_flex_width ) {
    		$dst['dst_height'] = $height;
    	} else {
    		$dst['dst_height'] = $theme_height;
    	}

    	if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) {
    		$dst['dst_width'] = absint( $width * ( $max_width / $width ) );
    	} elseif ( $has_flex_width && $has_flex_height ) {
    		$dst['dst_width'] = $width;
    	} else {
    		$dst['dst_width'] = $theme_width;
    	}

    	return $dst;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-custom-image-header.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-custom-image-header.php#L1270)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-custom-image-header.php#L1270-L1311)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#related)󠁿

| Uses | Description | 
| [get_theme_support()](https://developer.wordpress.org/reference/functions/get_theme_support/)`wp-includes/theme.php` |

Gets the theme support arguments passed when registering that support.

  | 
| [current_theme_supports()](https://developer.wordpress.org/reference/functions/current_theme_supports/)`wp-includes/theme.php` |

Checks a theme’s support for a given feature.

  | 
| [absint()](https://developer.wordpress.org/reference/functions/absint/)`wp-includes/load.php` |

Converts a value to non-negative integer.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#)

| Used by | Description | 
| [Custom_Image_Header::ajax_header_crop()](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_crop/)`wp-admin/includes/class-custom-image-header.php` |

Gets attachment uploaded by Media Manager, crops it, then saves it as a new object. Returns JSON-encoded object details.

  | 
| [Custom_Image_Header::step_3()](https://developer.wordpress.org/reference/classes/custom_image_header/step_3/)`wp-admin/includes/class-custom-image-header.php` |

Displays third step of custom header image page.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/custom_image_header/get_header_dimensions/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.9.0](https://developer.wordpress.org/reference/since/3.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fcustom_image_header%2Fget_header_dimensions%2F)
before being able to contribute a note or feedback.