Ready to get started?Download WordPress


Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp constrain dimensions


Calculates the new dimensions for a down sampled image.

If either width or height are empty, no constraint is applied on that dimension.


<?php wp_constrain_dimensions$current_width$current_height$max_width$max_height ); ?>


(int) (required) Current width of the image.
Default: None
(int) (required) Current height of the image.
Default: None
(int) (optional) Optional. Maximum wanted width.
Default: 0
(int) (optional) Optional. Maximum wanted height.
Default: 0

Return Values

First item is the width, the second item is the height.

Change Log

Since: 2.5

Source File

wp_constrain_dimensions() is located in wp-includes/media.php