The ext2type WordPress PHP filter allows you to modify the file type based on the extension name.
Usage
add_filter('ext2type', 'your_custom_function'); function your_custom_function($ext2type) { // your custom code here return $ext2type; }
Parameters
- $ext2type (array): Multi-dimensional array of file extensions types keyed by the type of file.
More information
See WordPress Developer Resources: ext2type
Examples
Add a new file type
Add a new file type for .xyz files as ‘custom’ type:
add_filter('ext2type', 'add_xyz_file_type'); function add_xyz_file_type($ext2type) { $ext2type['custom'][] = 'xyz'; return $ext2type; }
Modify an existing file type
Change .zip files from ‘compressed’ type to ‘custom’ type:
add_filter('ext2type', 'change_zip_file_type'); function change_zip_file_type($ext2type) { $ext2type['custom'][] = 'zip'; unset($ext2type['compressed']['zip']); return $ext2type; }
Remove a file type
Remove the .mp3 file type from the ‘audio’ category:
add_filter('ext2type', 'remove_mp3_file_type'); function remove_mp3_file_type($ext2type) { unset($ext2type['audio']['mp3']); return $ext2type; }
Combine multiple file types
Combine .jpg and .jpeg file types under the ‘image’ category:
add_filter('ext2type', 'combine_jpg_jpeg_file_types'); function combine_jpg_jpeg_file_types($ext2type) { $ext2type['image'][] = 'jpg'; $ext2type['image'][] = 'jpeg'; return $ext2type; }
Modify multiple file types
Move .docx and .xlsx files from ‘document’ type to ‘custom’ type:
add_filter('ext2type', 'move_docx_xlsx_file_types'); function move_docx_xlsx_file_types($ext2type) { $ext2type['custom'][] = 'docx'; $ext2type['custom'][] = 'xlsx'; unset($ext2type['document']['docx']); unset($ext2type['document']['xlsx']); return $ext2type; }