
Set separate width and height thresholds when WordPress’s default large-image handling does not suit your content.
WordPress 5.3 introduced automatic scaling for uploaded images larger than its default 2,560-pixel threshold. Our guide to disabling image scaling explains how to turn that behavior off. Keeping a reasonable limit can still help avoid unnecessarily large images.
The following filter changes the threshold to a single value:
// increase the image size threshold to 4000px
function mynamespace_big_image_size_threshold( $threshold ) {
return 4000; // new threshold
}
add_filter('big_image_size_threshold', 'mynamespace_big_image_size_threshold', 999, 1);That value applies to both width and height. A tall image may therefore be scaled to a width smaller than you expect. Displaying it at a larger width can then reduce its apparent sharpness.
The next example calculates a threshold using separate width and height limits. Add it to your functions.php file and adjust the values to suit your layout:
// Set Image Threshold for Both Width and Height
function custom_image_threshold($threshold, $imagesize) {
$width_threshold = 1920;
$height_threshold = 8000;
$image_width = $imagesize[0];
$image_height = $imagesize[1];
if ($height_threshold > $width_threshold) {
if ($image_height > $image_width) {
return min($image_height/$image_width * $width_threshold, $height_threshold);
}
return $width_threshold;
} else {
if ($image_width > $image_height) {
return min($image_width/$image_height * $height_threshold, $width_threshold);
}
return $height_threshold;
}
}
add_filter('big_image_size_threshold', 'custom_image_threshold', 10, 2);This approach gives you more control over how images with different proportions are scaled.
If you need help choosing image dimensions for your website, contact our team.
