Allow only Images uploaded in wordpress
When adding posts, we can upload media such as images, videos, word documentations, etc. If you want to know what types of media you can upload, just add following a single line of code to your functions.php, then go to your site and view the source and you’ll get a list of the media types.
[php]print_r(wp_get_mime_types());[/php]
So how can we restrict a specific media type, for example, we want to allow only images uploaded to the media library. Below is the snippet that can help us achieve this, just put it to your functions.php
[php]// Add the filter
add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
function custom_upload_mimes( $existing_mimes=array() ) {
$existing_mimes = array(‘jpg|jpeg|jpe’ => ‘image/jpeg’,
‘gif’ => ‘image/gif’,
‘png’ => ‘image/png’,
‘bmp’ => ‘image/bmp’,
‘tif|tiff’ => ‘image/tiff’,
‘ico’ => ‘image/x-icon’);
return $existing_mimes;
}[/php]