Restrict Certain File Mime Types in WordPress


I recently heard from a client saying their blog was loading very slowly. The issue was caused from a high resolution image in .tiff format which is generally used for print. In order to block these file types add the following plugin to your mu-plugins folder.

Source

<?php
/* prevent uploading of .tif files.
https://wordpress.stackexchange.com/questions/44777/upload-mimes-filter-has-no-effect
 
Full list of mime types
https://codex.wordpress.org/Function_Reference/get_allowed_mime_types
*/

add_filter( 'upload_mimes', 'theme_restrict_mime_types' );
function theme_restrict_mime_types( $mime_types )
{
    $mime_types = array(
        'pdf' => 'application/pdf',
        'doc|docx' => 'application/msword',
        'jpg|jpeg' => 'image/jpeg',
        'gif' => 'image/gif',
        'png' => 'image/png'
    );
    return $mime_types;
}

save as restrict-upload-types.php and upload to your mu-plugins folder.



Written by: Jake Lett
Jake Lett is a results-driven B2B marketing consultant with 15+ years of experience helping businesses boost online visibility, generate qualified leads, and increase sales. Specializing in SEO, HubSpot, and PPC campaign management, Jake leverages proven strategies to deliver measurable growth. As a Certified Google Ads Specialist and HubSpot Developer, he is committed to driving impactful results for his clients.

Related posts

Tags:

Want to Get Email Updates of New Articles?

Join My Email Newsletter