search ]

Restrict File Upload Types in WordPress

The following example will restrict file uploads in the media library to JPG and GIF files only. If you want to also allow PNG files, add the line 'png' => 'image/png' to this code:

function savvy_restrict_mime($mimes) {
    $mimes = array(
        'jpg|jpeg|jpe' => 'image/jpeg',
        'gif' => 'image/gif',
    );
    return $mimes;
}
add_filter('upload_mimes','savvy_restrict_mime');

More on this topic in the post How to allow uploading additional file types in WordPress?.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo