Skip to content

Instantly share code, notes, and snippets.

@barrd
Last active March 3, 2023 14:29
Show Gist options
  • Save barrd/3dc02351a073f778a688225dfdcc2918 to your computer and use it in GitHub Desktop.
Save barrd/3dc02351a073f778a688225dfdcc2918 to your computer and use it in GitHub Desktop.
WordPress enable AVIF file type
<?php
/**
* Enable AVIF types
*
* @see https://developer.wordpress.org/reference/functions/wp_check_filetype_and_ext/
*/
function barrd_enable_avif_types( $types, $file, $filename, $mimes ) {
if ( false !== strpos( $filename, '.avif' ) ) {
$types['ext'] = 'avif';
$types['type'] = 'image/avif';
}
return $types;
}
add_filter( 'wp_check_filetype_and_ext', 'barrd_enable_avif_types', 10, 4 );
/**
* Add mime type
*
* @see https://developer.wordpress.org/reference/hooks/upload_mimes/
*/
function barrd_enable_avif_mime( $mimes ) {
$mimes['avif'] = 'image/avif';
return $mimes;
}
add_filter( 'upload_mimes', 'barrd_enable_avif_mime' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment