If you are trying to upload EPUB to WordPress or sell EPUB files or other ebooks using WooCommerce, you might have come across one obscure little problem: WP doesn’t support EPUB by default. You might be having trouble uploading EPUB files to your WP Media Library with a “This file cannot be processed by the web server” error message, and/or you might run into the “Invalid download link” error screen when you try to download your WooCommerce EPUB. If you look closely at your WooCommerce product file list, you might see the extremely subtle red asterixes next to your files it has disabled. If the EPUB MIME type isn’t active, then all your EPUB files will be disabled automatically.
These clues are subtle enough as to become maddening, but don’t worry, there’s a quick fix.
To fix this, you’ll need to instruct WP to support EPUB using a little bit of code. Here is the PHP snippet to add the EPUB MIME type:
/**
* Add the 'epub' MIME type to the existing WP MIME list
* @param array $mimes
* @return array
*/
function add_epub_mime_to_wp( $mimes ) {
$mimes['epub'] = 'application/epub+zip';
// other mime types, like mobi, could be added below, like:
// $mimes['mobi'] = 'application/x-mobipocket-ebook';
return $mimes;
}
add_filter( 'upload_mimes', 'add_epub_mime_to_wp' );
This code can be added to the bottom of your WP (child) theme functions.php file using FTP/SSH, or your File Manager of choice. Alternatively you can use the WordPress plugin called Code Snippets to add the code to your WP installation so that WP parses it on every page load. Or if you want to skip adding what could be just 5 lines of code to your site, you can add hundreds instead by installing yet another plugin that will do something for you once you master its settings. 😉
A human wrote this blog post. Thanks for reading! 🙂