Enabling EPUB for WP and WooCommerce

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. If you’re using PDF Ink, just check the box in the Integration Settings that says “Facilitate WP EPUB uploads.” You’re done.

If you’re not using PDF Ink…

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/prc, could be added below, like so:
  // $mimes['mobi'] = 'application/x-mobipocket-ebook';
  // $mimes['prc'] = '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. 😉

If you’ve added this code to your WP site, and uploads still aren’t working, you might try adding these lines to your .htaccess file (if you’ve got an Apache server). You can also view active MIME types in the “MIME Types” section of your cPanel (under “Advanced”).

AddType application/epub+zip .epub
AddType application/x-mobipocket-ebook .mobi
AddType application/x-mobipocket-ebook .prc

If you’re not on an Apache server or this goes over your head, reach out to your hosting provider support channel for help.

A human wrote this blog post. Thanks for reading! 🙂