Want to know what WordPress Theme a site is using? Check Out Now!

How to Allow EPUB File Uploads in WordPress?

Do you want to allow EPUB file uploads on your WordPress website?

WordPress allows you to upload audio, video, and image file formats by default. WordPress doesn’t offer EPUB file uploads due to security reasons and you may encounter an error while uploading the EPUB file to the WordPress media library.

Allow EPUB File Uploads For All Users

If you want to enable the EPUB file uploads in WordPress, use the code below.

/**
 * Allow EPUB file upload in WordPress
 */
function maverick_allow_epub_file_mime_types($mimes)
{

    $mimes['epub'] = 'application/epub+zip';

    return $mimes;
}

add_filter('upload_mimes', 'maverick_allow_docs_mime_types');

Allow EPUB File Uploads Only For Administrators

Since uploading EPUB files can put your site at risk, you can restrict EPUB file upload to Site Administrators. You can use the below code to allow EPUB file uploads only by administrators.

/**
 * Allow EPUB file upload in WordPress
 */
function maverick_allow_epub_file_mime_types($mimes)
{

    //Only allow SVG upload by admins
    if (!current_user_can('administrator')) {
        return $mimes;
    }

    $mimes['pdf'] = 'application/pdf';

    return $mimes;
}

add_filter('upload_mimes', 'maverick_allow_docs_mime_types');

Leave a Reply

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