Filter Hook since 2.0.0
upload_mimes
Filters the list of file types allowed for upload
Description
upload_mimes controls what get_allowed_mime_types() and the uploader accept — adding a type here does not make it safe by itself; WordPress still runs its own file-content checks.
When it runs
Whenever WordPress checks allowed upload types — the media uploader, wp_check_filetype(), and REST media endpoints.
Signature
apply_filters( 'upload_mimes', array $mime_types, WP_User|int|null $user );Parameters
$mime_typesarray — Allowed mime type => extension pattern pairs.$userWP_User|int|null — User the check is being made for, if any.
Examples
Basic
add_filter( 'upload_mimes', function( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
} );Allow SVG uploads through the media library.
Common Use Cases
- Allow SVG or other blocked file types
- Restrict uploads to a smaller set of types by role
- Add support for a niche file format
Common mistakes
- Allowing SVG uploads without sanitizing them — SVG can contain embedded scripts, a real XSS risk
Related hooks
FAQ
Is it safe to allow SVG uploads with this filter alone?
No — pair it with an SVG sanitizer library or plugin. The raw filter only changes what's accepted, not what's safe.
Source: wp-includes/functions.php