WordPress:每张添加的照片都会创建许多不同大小的不同照片 [英] Wordpress: Each added photo creates a lot of different photos in different sizes

查看:113
本文介绍了WordPress:每张添加的照片都会创建许多不同大小的不同照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在WooCommerce列表中添加新产品照片时,它会创建许多不同尺寸的不同照片,例如xproduct.png,xproduct-80x80.png,xproduct-480x480.png,xproduct-720x720.png等

When I add a new product photo in the WooCommerce list, it creates a lot of different photos in different sizes such as xproduct.png, xproduct-80x80.png, xproduct-480x480.png, xproduct-720x720.png, etc.

我不知道这个问题的核心在哪里。 WordPress或WooCommerce是否有问题?
我该如何解决?我的数据库中充满了这些不必要的照片。

I don't know where is the core of this problem. Do I have problems with WordPress or WooCommerce? How can I fix this? My database is full of these unnecessary photos.

例如;
我有100个产品,每个产品有10张照片,但是每张照片会创建10张不同的照片,最后,我只为一个产品提供100张照片。这意味着我有100张产品的1,000张照片。

For example; I have 100 products with 10 photos for each, but it creates 10 different photos for each photo, and finally, I have 100 photos for just one product. It means that I have 1,000 photos for 100 products.

推荐答案

WordPress默认情况下会生成3种图像大小(缩略图,中,大)并保留原始图像大小('充分')。

WordPress generates 3 image sizes by default ('thumbnail', 'medium', 'large') and keeps the original one ('full').

但是任何主题或插件都可以注册自己的大小以用于不同目的。通常使用 add_image_size() 核心功能

But any theme or plugin can register its own sizes for different purposes. New sizes are typically added with add_image_size() core function.

如果主题/插件生成了过多的图像,则可以轻松删除不必要的图像。

If your theme/plugins generate excessive image sizes, you can remove unnecessary rather easily.


  1. 首先,您需要找出已注册的尺寸。 这是一个函数,您可以为此使用: get_intermediate_image_sizes ()

  2. 第二,您需要使用 remove_image_size() 功能覆盖未使用尺寸的注册。您应该及时调用它(在注册之后。但是在任何输出开始之前),因此您可能会调用一个钩子。

  1. First, you need to find out which sizes are already registered. Here is a function you can use for that: get_intermediate_image_sizes().
  2. Second, you need to use remove_image_size() function to override the registration of unused sizes. You should call it right in time (after the registration. but before any output starts), so you'll probably call a hook.

此示例删除了所有图像大小,但允许的大小除外:

This example removes all image sizes except the allowed ones:

function remove_unused_image_sizes() {

    $allowed_sizes = array( 'thumbnail', 'medium', 'large' );
    $registered_sizes = get_intermediate_image_sizes();

    foreach ( $registered_sizes as $size ) {
        if ( ! in_array( $size, $allowed_sizes ) ) {
            remove_image_size( $size );
        }
    }
}

add_action('init', 'remove_unused_image_sizes');

然后,您可能想运行一些更简洁的插件(例如媒体清理器)以删除现有的未使用文件和数据库记录。

Then you might want to run some cleaner plugins (e.g. Media Cleaner) to remove existing unused files and database records.

这篇关于WordPress:每张添加的照片都会创建许多不同大小的不同照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆