Last active
March 3, 2023 14:29
-
-
Save barrd/3dc02351a073f778a688225dfdcc2918 to your computer and use it in GitHub Desktop.
WordPress enable AVIF file type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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