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

  1. 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.

Comments

  1. Hi Pau,

    Not sure what your issue could be, it works perfectly on my localhost version of WordPress, here are some suggestions:

    1. When you modified your theme’s function.php file did you remember to save + upload the new file to production?
    2. Maybe there’s another conflicting function (in functions.php) using the upload_mimes hook.
    3. If you have multiple themes, make sure you edit your active theme’s functions.php file.

    Cheers.

  2. 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.

  3. 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.

Leave a Reply

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