If you’ve ever tried to upload an image in WordPress that has large dimensions, you may have noticed that the resulting file has smaller dimensions than the original image.
This is because WordPress has a threshold for the maximum image dimensions, and if your image is higher than that threshold, it will get scaled.
You may want to upload large dimension images, such as a background image that looks great on very large monitors. Read on to find out how to amend the image upload threshold in WordPress.
Table of Contents
What is the big image size threshold?
When you upload an image via WordPress, it will check if the width or height is above the default threshold of 2560px. If the image is larger than this, it will reduce the dimensions to be within this threshold.
It does this as generally you don’t want really large images being uploaded, which are likely to have a huge file size and therefore can make the page the image is added to take much longer to load. However, you might want to increase or decrease this threshold in some scenarios.
For example, let’s say you have a theme option that allows you to upload a background image used across the website. You’ve optimised this image yourself to a small file size, even though the dimensions are above the threshold. You want to use the image at the original dimensions to ensure the background looks good on larger monitors.
For this scenario, you might want to consider adjusting the threshold or disabling it altogether.
How can I disable or amend the threshold?
Image uploads via WordPress get passed through a filter hook to check if the image width or height is larger than the threshold, if it is, the the image will get scaled.
This filter hook is big_image_size_threshold. As this is a filter hook, you can use it to return a different threshold value.
Disable the threshold
To do this, add the following code snippet to your website. For info on how to add code snippets see here.
add_filter( 'big_image_size_threshold', '__return_false' );
The '__return_false'
will disable the scaling entirely.
Amend the threshold
If you want to increase or decrease the threshold, you can specify an integer instead, like this:
function yourprefix_big_image_size_threshold( $threshold ) {
return 4000;
}
add_filter( 'big_image_size_threshold', 'yourprefix_big_image_size_threshold' );
Check the results
Once you’ve added one of the code snippets above, try it out by uploading an image that has large dimensions. If you disabled the threshold, then it should have the original dimensions. If you amended the threshold, the image should be scaled to the new threshold you’ve set.