• By default WordPress doesn’t overwrite an existing image if image is edited using built-in image editor, instead of that, new image file is created.

    For example, image file: image-file-name.jpg is edited, (for example simple crop/resize), new file is created on disk with some random characters at the end of file name, like this image-file-name-655f4dgfd4g4f.jpg

    New image will be used in page/post, but old file will stay on disk, but not used at all. I can’t see option to delete old file, or even to list it/see it. You can delete old image(s) only from FTP.

    Is there any function (for functions.php) which will tell WP to replace original image with edited image (or to delete original image after editing).

Viewing 2 replies - 1 through 2 (of 2 total)
  • AddWeb Solution

    (@addweb-solution-pvt-ltd)

    You have to use this filter in your function.php or your plugin file which you are using upload image.

    add_filter('wp_generate_attachment_metadata', 'img_delete_fullsize_image');
    
    function img_delete_fullsize_image($metadata)
    {
        $upload_dir = wp_upload_dir();
        $full_image_path = trailingslashit($upload_dir['basedir']) . $metadata['file'];
        $deleted = unlink($full_image_path);
    
        return $metadata;
    }
    Thread Starter Advanced SEO

    (@jole5)

    It is not working.
    I put your code into functions.php inside my theme folder. After that, when I upload new image to post, and if I wish to edit that image using built in WP image editor, I can not see that image, just blank place where image should be, and I get this error:

    Could not load the preview image. Please reload the page and try again.

    I can not edit original image, to see if this your code then do what it should, to replace/delete original image.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP image editor, replace original image?’ is closed to new replies.