-
-
Save MyListingClub/3e1a7c6205ac70a011f6b10f9e9ce090 to your computer and use it in GitHub Desktop.
functions.php | Limit Image Upload Size
This file contains 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
//// INSTRUCTIONS: | |
//// Copy and paste the code snippet below into the child theme's functions.php file. | |
//// You can edit the functions.php file from your WordPress dashboard (Appearance > Theme Editor) or via FTP. | |
//// NOTES: | |
//// Adjust each instance of "600" (i.e. 600KB) value as desired. | |
//// Adjust each instance of "600KB" for a cosmetic-only reference that matches your actual file size limit. | |
---------------------------CODE SNIPPET IS BELOW THIS LINE--------------------------------------------------------- | |
// LIMIT IMAGE UPLOAD SIZE | |
function max_image_size( $file ) { | |
$size = $file['size']; | |
$size = $size / 600; | |
$type = $file['type']; | |
$is_image = strpos( $type, 'image' ) !== false; | |
$limit = 600; | |
$limit_output = '600KB'; | |
if ( $is_image && $size > $limit ) { | |
$file['error'] = 'Image files must be smaller than ' . $limit_output; | |
}//end if | |
return $file; | |
}//end max_image_size() | |
add_filter( 'wp_handle_upload_prefilter', 'max_image_size' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment