Restrict uploads to specified file types only, jpg, gif

Adding this snippet to the functions.php of your wordpress theme will allow you to restrict uploads to an array of specified mime types only. This sample only allows jpg and gif images, adding a new line for png eg: ‘png’ => ‘image/png’, would then allow png images.




function restrict_mime($mimes) {
$mimes = array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
return $mimes;

Leave a comment