Created
August 21, 2017 09:15
-
-
Save davilera/6e954e3684cf8c249967a3bf0bb5701e to your computer and use it in GitHub Desktop.
WordPress Image Size Limit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nelio_max_image_size( $file ) { | |
$size = $file['size']; | |
$size = $size / 1024; | |
$type = $file['type']; | |
$is_image = strpos( $type, 'image' ) !== false; | |
$limit = 250; | |
$limit_output = '250kb'; | |
if ( $is_image && $size > $limit ) { | |
$file['error'] = 'Image files must be smaller than ' . $limit_output; | |
}//end if | |
return $file; | |
}//end nelio_max_image_size() | |
add_filter( 'wp_handle_upload_prefilter', 'nelio_max_image_size' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment