Code to Disallow Uploading of Specific File Types in WordPress

/* Disallow Uploading of Specific File Types */
function wpflt_disallow_custom_file_types( $mimes ) {
unset( $mimes['exe'] );
unset( $mimes['otf'] );
unset( $mimes['psd'] );
unset( $mimes['ppt'] );
unset( $mimes['webp'] );
return $mimes;
}
add_filter( 'upload_mimes', 'wpflt_disallow_custom_file_types' );

If you want to disallow some specific file type from being uploaded to media folder in WordPress, add the above code to your child theme’s functions.php.

Examples:

To disable uploading of PNG image file types, add the below line to the above code.

unset( $mimes['png'] );

Disable Uploading of PDF files to WordPress Media folder

unset( $mimes['pdf'] );

Warning 🙂

However, users/ admins can upload and place restricted files in any other directory inside the public_html (with necessary permissions). Viewers can download those files if links are provided and files are accessible.

Also Read,

Allow support for more known file types in WordPress