Select Page

This can be used to set a maximum image upload size in WordPress, this helps to stop clients uploading large image files.

This example is 1.5mb

//limit image file size to 1.5mb
function whero_limit_image_size($file) {
// Calculate the image size in KB
$image_size = $file['size']/1024;
// File size limit in KB
$limit = 1500;
// Check if it's an image
$is_image = strpos($file['type'], 'image');
if ( ( $image_size > $limit ) && ($is_image !== false) )
        $file['error'] = 'Your picture is too large. It has to be smaller than '. $limit .'KB';
return $file;
add_filter('wp_handle_upload_prefilter', 'whero_limit_image_size');