Snippet: Restrict Mime Types on WordPress Media Upload

Add following snippet to “functions.php”

Snippet

add_filter( 'upload_mimes', 'restrict_mime_types_func' );
add_action( 'post-upload-ui', 'restrict_mime_types_hint_func' );
function fb_restrict_mime_types( $mime_types ) {
    $mime_types = array(
        'pdf' => 'application/pdf',
        'doc|docx' => 'application/msword',
    );

    return $mime_types;
}
function fb_restrict_mime_types_hint() {
    echo '<br />';
    _e( 'Accepted MIME types: PDF, DOC/DOCX' );
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>