The big_image_size_threshold WordPress PHP filter allows you to modify the threshold value for “BIG images”. If the original image width or height is above the threshold, it will be scaled down. The threshold is used as max width and max height. The scaled down image will be used as the largest available size, including the _wp_attached_file post meta value. Returning false from the filter callback will disable the scaling.
Usage
add_filter('big_image_size_threshold', 'your_custom_function', 10, 4); function your_custom_function($threshold, $imagesize, $file, $attachment_id) { // your custom code here return $threshold; }
Parameters
$threshold
(int) – The threshold value in pixels. Default 2560.$imagesize
(array) – Indexed array of the image width and height in pixels.- 0 (int) – The image width.
- 1 (int) – The image height.
$file
(string) – Full path to the uploaded image file.$attachment_id
(int) – Attachment post ID.
More information
See WordPress Developer Resources: big_image_size_threshold
Examples
Increase the threshold value
To increase the threshold value for “BIG images” to 3000 pixels:
add_filter('big_image_size_threshold', 'increase_big_image_threshold', 10, 4); function increase_big_image_threshold($threshold, $imagesize, $file, $attachment_id) { $threshold = 3000; return $threshold; }
Disable “BIG image” scaling
To disable the scaling of “BIG images”:
add_filter('big_image_size_threshold', '__return_false');
Change the threshold value based on file type
To set a different threshold value for JPEG images:
add_filter('big_image_size_threshold', 'jpeg_big_image_threshold', 10, 4); function jpeg_big_image_threshold($threshold, $imagesize, $file, $attachment_id) { if (mime_content_type($file) == 'image/jpeg') { $threshold = 3000; } return $threshold; }
Set a different threshold value for vertical images
To set a different threshold value for images that are taller than they are wide:
add_filter('big_image_size_threshold', 'vertical_image_threshold', 10, 4); function vertical_image_threshold($threshold, $imagesize, $file, $attachment_id) { if ($imagesize[1] > $imagesize[0]) { $threshold = 2000; } return $threshold; }
Apply threshold value based on user role
To apply a different threshold value for “BIG images” uploaded by users with the ‘editor’ role:
add_filter('big_image_size_threshold', 'editor_big_image_threshold', 10, 4); function editor_big_image_threshold($threshold, $imagesize, $file, $attachment_id) { $user = wp_get_current_user(); if (in_array('editor', $user->roles)) { $threshold = 3500; } return $threshold; }