Uploading AVIF images in WordPress
By default, WordPress doesn’t support uploading of AVIF images to the media library. Luckily this is super easy to fix with a minor addition to your theme’s functions.php
file and a helpful plugin.
The Solution
- Add the following PHP code to your theme’s
functions.php
file:
function cmyee_allowed_mime_types( $mime_types ) {
//AVIF Images
$mime_types['avif'] = 'image/avif';
return $mime_types;
}
add_filter( 'upload_mimes', 'cmyee_allowed_mime_types', 1, 1 );
2. Download & activate the Lord of the Files: Enhanced Upload Security plugin.
3. That’s it! Now you can upload AVIF images in the WordPress media library.
Hi Chris,
I’m trying to follow your steps… But it doesn’t work to me.
Hi Pau,
Not sure what your issue could be, it works perfectly on my localhost version of WordPress, here are some suggestions:
If you have multiple themes, make sure you edit your active theme’s functions.php file.
Cheers.
Hi Chris, I’ve tried it and works
But when setup in single page the image didn’t appear, and if I publish the page, the image was lost
I did as you wrote and it worked. I just want to note that the code in functions.php must be inserted by the rest of the above so that it is the first to go into action. That’s the only way it works.
Thanks for the description and the plugin. Unfortunately, automatically generated thumbnails in the media library I can see only conditionally. But “around the front”, where the images should do their job, everything is okay. I guess it all depends on the individual WordPress configuration. With my configuration I’m lucky that the “AVIF combination” essentially works. Thanks again.