Allow WEBP and Other File Types to be Uploaded in WordPress

Categories:

WordPress allows a number of file types to be uploaded by default (e.g. PNG, JPG, etc.). For the file types that are not allowed, it will display an error message when you try to upload them: “Sorry, this file type is not permitted for security reasons.”

To allow other file types to be uploaded, you need to add the following code to the functions.php file of your theme (in this case we will allow .webp):

function custom_myme_types($mime_types){
    $mime_types['webp'] = 'image/webp'; 
    return $mime_types;
}
add_filter('upload_mimes', 'custom_myme_types', 1, 1);

Another solution, which I don’t recommend but may be useful for troubleshooting purposes, is to allow all files to be uploaded by adding a line to the wp-config.php file:

define('ALLOW_UNFILTERED_UPLOADS', true);

Just wanted to mention the second solution, but I hope you choose to use the first one 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *