Created
June 17, 2018 03:43
-
-
Save geoluther/d529a2125ba633d23387142adf8e3a67 to your computer and use it in GitHub Desktop.
limit wordpress image size
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