Skip to content

Instantly share code, notes, and snippets.

@geoclaps
Created September 19, 2018 14:41
Show Gist options
  • Save geoclaps/1f4a51be21471d650feac9af93e4abf6 to your computer and use it in GitHub Desktop.
Save geoclaps/1f4a51be21471d650feac9af93e4abf6 to your computer and use it in GitHub Desktop.
Wordpress upload limit
function upload_limits($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;
}
return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'upload_limits' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment