Support » Plugin: WebP Converter for Media » How to set generated WebP directory to be same as source?

  • Resolved brandontan903


    Currently, /wp-content/uploads/2019/06/example.jpg will generate:

    Is it possible to set the generated WebP directory to be the same directory as the source?

    So that /wp-content/uploads/2019/06/example.jpg will generate:

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mateusz Gbiorczyk


    Hi @brandontan903,

    Thank you for your message.

    Why do you want to do that?

    The files are saved in a separate directory specifically. Thanks to this, there is no risk of overwriting your original files.

    Additionally when you decide you want to uninstall the plugin you can delete everything. When the files generated by the plugin are removed, the uploads-webp directory is removed and I have the guarantee that I will not delete any of your files.

    The problem is: the HTML’s img replacement

    I want to do exception for gif since the generated webp is not animated.

    But not yet found how can I exclude gif uploads from being replaced by uploads-webpc.

    Below is my functions to replace data in HTML img tag (I’m using lazy-loading. So it is data-src):

    if (!is_admin()) {
        if ( strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false ) {
            function callback_webp($buffer) {
                $toreplace = array(
                $withtext = array(
                return (str_replace($toreplace, $withtext, $buffer));
    Plugin Author Mateusz Gbiorczyk


    On the plugin’s settings page you can set formats. By default, .gif is disabled.

    Why do you want to change links in img HTML tag? The links may remain original. Your .htaccess file itself will convert the source file. If the browser supports WebP, instead of the .png file, the .png.webp file will show up, despite the fact that the link will remain the same.

    I’ve enabled the gif option in the setting page, but it cannot produce animated WebP from uploaded animated gif.

    I able to do exception by web server rewrite (nginx) but prefer using PHP.

    Plugin Author Mateusz Gbiorczyk


    These are library restrictions, so you can turn off the .gif format.

    Why do you prefer PHP?

    I personally prefer cleaner HTML codes and no redirect if possible.

    Thanks a lot for your feedback.

    Plugin Author Mateusz Gbiorczyk


    Hi @brandontan903,

    Redirections have no negative impact. This is just a change of the MIME type of the file and the path to it.

    And you get thanks to this:
    – cache support (when you save a page with URLs to WebP images to the cache and then use Safari for example, a problem will appear because Safari does not support WebP)
    – in the PHP code you do not check if a .webp file exists (it may happen that some file has not been converted and you will get a 404 error)
    – changing links in PHP affects the website’s performance
    – storing .webp files in the uploads directory causes you to combine source files with converted files (splitting makes source in one location, and converted versions in another)

    Can I still do to help you?

    I just wanted to install this plugin but I better not because I want my webp files in exactly same directory.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.