• Resolved DianaCC

    (@dianacc)


    Hi!

    I’ve been trying to upload an epub file, but I get an error (it says it’s not possible to upload it for security reasons).

    After checking with my hosting provider that it’s not a problem of upload limit, it seems I should insert a specific code line in functions.php, in Editor. I found this piece of code in the blog of someone who had the same problem, buy they were not using the Virtue Theme, so I don’t know if that would work in my case:

    function addUploadMimes($mimes) {
    $mimes = array_merge($mimes, array(
    ‘epub|mobi’ => ‘application/octet-stream’
    ));
    return $mimes;
    }
    add_filter(‘upload_mimes’, ‘addUploadMimes’);

    Does anyone know what piece of code exactly I should insert (considering I’m using Virtue) and where? I would be so grateful!

    Thanks,
    Diana

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hey there Diana,

    Hope you’re well! ??

    The code you posted above is correct and the one you need to allow upload of .epub file extension. To do that follow the instruction below:

    Use child themes for any customisation you will make. Read more about it here: https://codex.www.ads-software.com/Child_Themes

    Put this code inside your functions.php or use Code Snippet plugin

    function addUploadMimes($mimes) {
    
    	$mimes = array_merge($mimes, array(
    	'epub|mobi' => 'application/octet-stream'
    	));
    	return $mimes;
    
    }
    
    add_filter('upload_mimes', 'addUploadMimes');

    Let me know if it helps! ??

    Best Regards,
    Calvin

    Thread Starter DianaCC

    (@dianacc)

    Thank you so much, Calvin ??

    I almost finished creating a virtue-child theme (after some hours of work… I’m quite unexperienced, as you can see!), but now it appears as a “broken theme” in my themes.

    The error message says there is no parent theme… But I followed carefully all the steps (creating the directory, creating the style.css and functions.php files…), so I don’t know where the problem is. How do I indicate that Virtue is the parent of the new child theme?

    Maybe there is an error in the style.css or function.php?

    Here is the code I included in the style.css:
    /*
    Theme Name: Virtue Child
    Theme URI: https://bonport.cat/virtue-child/
    Description: Virtue Child Theme
    Author: D.Coromines
    Author URI: https://bonport.cat/
    Template: Virtue
    Version: 2.3.3
    License: GNU General Public License v3.0
    License URI: https://www.gnu.org/licenses/gpl.html
    Tags: responsive-layout, two-columns, one-column, custom-colors, custom-header, custom-menu, featured-images, translation-ready, theme-options, photoblogging
    Text Domain: virtue-child
    */

    And here the code I included in functions.php file so far:
    <?php

    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
    function theme_enqueue_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );

    }

    ?>

    Sorry because this is a bit off-topic (not corresponding to the title -uploading epubs), but thanks to your piece of advice Calvin I realised the first thing to do was to solve the child theme problem…

    Diana

    You have: Template: Virtue

    but it should be: Template: virtue

    Kadence Themes

    Thread Starter DianaCC

    (@dianacc)

    It worked, thank you so much!

    Now I only need to paste the code to allow upload of .epub file extension. I went to functions.php (in my virtue child theme in WordPress Editor) and I pasted it there, but probably not in the right spot cause it didn’t work (it gave a “fatal error”). Here is where I put the piece of code:

    <?php

    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
    function theme_enqueue_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );

    }

    function addUploadMimes($mimes) {

    $mimes = array_merge($mimes, array(
    ‘epub|mobi’ => ‘application/octet-stream’
    ));
    return $mimes;

    }

    add_filter(‘upload_mimes’, ‘addUploadMimes’);

    ?>

    Isn’t that right? Could you tell me where exactly I should paste it?

    Again, thanks a lot…

    Diana

    I don’t see anything wrong with the code, although you don’t need this:

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    }

    That can be removed.

    As for supporting epub it’s not really anything theme specific. If the code you found doesn’t work for you then I would try approaching this through the htaccess files. Adding the file type. I am surprised your hosting company didn’t have a easy fix for you.

    Kadence Themes

    Thread Starter DianaCC

    (@dianacc)

    I removed that piece of code and… this time it worked! I could finally upload my epub file ??

    Thank you so much, Calvin and Kadence, for your help ??
    Diana

    Hello Diana and Kadence.

    @dianna

    Glad it’s working for you! ??

    @Kadence

    Thanks for helping out here ??

    Take care,
    Calvin

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problems with uploading epub files’ is closed to new replies.