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.

 

 

 

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

Be Sociable, Share!

Leave a comment