Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@davilera
Created August 21, 2017 09:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save davilera/6e954e3684cf8c249967a3bf0bb5701e to your computer and use it in GitHub Desktop.
Save davilera/6e954e3684cf8c249967a3bf0bb5701e to your computer and use it in GitHub Desktop.
WordPress Image Size Limit
<?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