如何清理您的WordPress媒体库(2种简单方法)

本文介绍了如何清理WordPress媒体库以节省主机服务器的磁盘空间和减少备份大小,包括使用Media Cleaner和Media Deduper插件的方法,并强调清理前确保有完整备份的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Do you want to clean up your WordPress media library? WordPress makes several copies of media files that up load, and over time this leads to a ton of files in storage that are not used anywhere on your website.

您是否要清理WordPress媒体库? WordPress会制作几份上传的媒体文件副本,随着时间的流逝,这会导致大量存储文件在您的网站上未使用。

Cleaning up your WordPress media library saves disk space on your hosting server and reduces backup sizes (both of which will help you save cost).

清理WordPress媒体库可节省托管服务器上的磁盘空间,并减少备份大小(这两者都将帮助您节省成本)。

In this article, we will show you how to easily clean up your WordPress media library step by step.

在本文中,我们将逐步向您展示如何轻松清理WordPress媒体库。

Cleaning up WordPress media library
为什么要清理WordPress媒体库? (Why Clean Up WordPress Media Library?)

WordPress creates several copies of each image you upload to your website. WordPress themes and plugins may also request additional image sizes.

WordPress会为您上传到网站的每个图像创建多个副本。 WordPress主题和插件也可能要求其他图像尺寸

Apart from these image sizes, you may also end up uploading a ton of images that are not really used anywhere on your website.

除了这些图像尺寸之外,您还可能最终上传了大量网站上未真正使用的图像。

These media files take up disk space on your WordPress hosting server. They also increase your WordPress backup sizes, which means it takes longer to backup, transfer, and restore your website.

这些媒体文件占用了WordPress托管服务器上的磁盘空间。 它们还会增加您的WordPress备份大小,这意味着备份,传输和还原您的网站需要更长的时间。

If you have been running a WordPress website for some time, then you can benefit from cleaning up the WordPress media library.

如果您已经运行WordPress网站已有一段时间,那么可以从清理WordPress媒体库中受益。

That being said, let’s take a look at how to easily clean up the WordPress media library.

话虽如此,让我们看一下如何轻松清理WordPress媒体库。

For this tutorial, we will cover two different plugins, and you can choose the one that looks easier.

在本教程中,我们将介绍两个不同的插件,您可以选择一个看起来更简单的插件。

Note: You will be cleaning up unused media files by deleting them forever. This action cannot be undone. Make sure that you have a complete WordPress backup in place before proceeding further.

注意:您将通过永久删除未使用的媒体文件来清理它们。 此操作无法撤消。 在继续进行操作之前,请确保已准备好完整的WordPress备份

影片教学 (Video Tutorial)

演示地址

If you’d prefer written instructions, just keep reading.

如果您喜欢书面说明,请继续阅读。

方法1.使用媒体清理器清理WordPress媒体库 (Method 1. Clean up WordPress Media Library using Media Cleaner)

For this method, we will be using the Media Cleaner plugin. It is available as a free plugin with a pro version available with some more features.

对于这种方法,我们将使用Media Cleaner插件。 它是一个免费插件,具有专业版并提供更多功能。

First, thing you need to do is install and activate the Media Cleaner plugin. For more details, see our step by step guide on how to install a WordPress plugin.

首先,您需要做的是安装并激活Media Cleaner插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, go to Media » Cleaner page to analyze your WordPress media library. The plugin may ask you to reset itself, during this process it will create a new table in your WordPress database to store data.

激活后,转到Media»Cleaner页面以分析您的WordPress媒体库。 插件可能会要求您重置自身,在此过程中,它将在WordPress数据库中创建一个新表来存储数据。

After that, you need to click on the Start Scan button to run the media analysis.

之后,您需要单击开始扫描按钮以运行媒体分析。

Media Cleaner

Media Cleaner will now look for files in your media library and inside your WordPress posts / pages. It will try and find the files that are in your media library but are not used on your website.

Media Cleaner现在将在您的媒体库和WordPress帖子/页面中查找文件。 它将尝试查找您的媒体库中但未在您的网站上使用的文件。

This may take a while depending on the size of your media library and the content you have.

这可能需要一段时间,具体取决于媒体库的大小和所包含的内容。

Once finished, you’ll see a list of results. It will show you all the media files that are not currently in use on your website.

完成后,您将看到结果列表。 它将显示您网站上当前未使用的所有媒体文件。

Media cleaner results

You can select the files that you don’t want to keep and delete them. You can also click on the Delete All button to instantly delete all unused media files.

您可以选择不想保留的文件并将其删除。 您也可以单击全部删除按钮立即删除所有未使用的媒体文件。

使用Media Deduper清理WordPress Media Library (Clean Up WordPress Media Library using Media Deduper)

For this method, we will be using the Media Deduper plugin. It is also available as both a free and paid version.

对于这种方法,我们将使用Media Deduper插件。 它也有免费和收费版本。

However, we recommend using the pro version because it allows you to prevent deleting duplicate images in the WordPress gallery, Yoast SEO, WooCommerce, and more.

但是,我们建议您使用专业版,因为它允许您防止删除WordPress图库,Yoast SEO, WooCommerce等中的重复图像。

First, you need to install and activate the Media Deduper plugin. For more details, see our step by step guide on how to install a WordPress plugin.

首先,您需要安装并激活Media Deduper插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to visit Media » Manage Duplicates page and click on the Index Media button to analyze your media library.

激活后,您需要访问媒体»管理重复页面,然后单击索引媒体按钮来分析您的媒体库。

Manage duplicates

The plugin will start analyzing your media library and will list all the duplicate images. You can then see if a duplicate image is used on your website.

该插件将开始分析您的媒体库,并将列出所有重复的图像。 然后,您可以查看您的网站上是否使用了重复的图像。

After reviewing the files, you can select all files or specific duplicates. Next, simply select ‘Smart Delete’ from the Bulk actions drop-down menu and then click the Apply button.

查看文件后,您可以选择所有文件或特定的重复项。 接下来,只需从“批量操作”下拉菜单中选择“智能删除”,然后单击“应用”按钮即可。

Smart delete

Smart Delete feature will make sure that images that are being used on your website are not deleted. It will also merge duplicate images allowing you to reuse media files without reuploading the same file.

智能删除功能将确保不会删除您网站上正在使用的图像。 它还将合并重复的图像,使您可以重用媒体文件,而无需重新上传同一文件。

优化您的媒体文件 (Optimizing Your Media Files)

Now that you have taken care of the duplicate images on your website, the next step is to optimize your existing media files.

现在您已经处理了网站上的重复图像,下一步是优化现有的媒体文件。

A lot of beginners, directly upload images from their phones and cameras. These high-quality images are often too big in filesize. They take up disk space, increase backup sizes, and affect WordPress speed and performance.

很多初学者直接从手机和相机上传图像。 这些高质量图像的文件大小通常太大。 它们占用磁盘空间,增加备份大小,并影响WordPress的速度和性能

You can use a WordPress image compression plugin to automatically optimize your media files without losing quality. You can also use our tips on how to optimize images for web performance before you upload them on your site (this is much better).

您可以使用WordPress图像压缩插件自动优化媒体文件,而不会降低质量。 您还可以在将图片上传到网站上之前,使用我们的技巧来优化图片以提高网络性能 (这会更好)。

We hope this article helped you learn how to clean up the WordPress media library. You may also want to see our guide on how to clean up your WordPress database.

我们希望本文能帮助您学习如何清理WordPress媒体库。 您可能还想查看有关如何清理WordPress数据库的指南

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/plugins/how-to-clean-up-your-wordpress-media-library/

### Cursor 测试常见问题及解决方案 #### 初始化游标失败 当尝试创建或初始化游标对象时可能出现异常。这通常是因为数据库连接未成功建立或是参数传递错误。 ```python import aioodbc async def init_cursor(): dsn = 'Driver=SQL Server;Server=localhost;Database=testdb;' try: conn = await aioodbc.connect(dsn=dsn, loop=loop) cur = await conn.cursor() # 创建游标的语句可能引发异常 print("Cursor created successfully.") except Exception as e: print(f"Failed to create cursor: {e}") ``` 如果遇到此类情况,建议验证DSN字符串中的服务器名、数据库名称以及驱动程序是否正确无误[^5]。 #### 执行查询后无法获取结果集 有时执行完 SQL 查询命令之后发现读取不到预期的数据记录。这种情况可能是由于忘记等待协程完成或者是没有正确调用 fetch 方法所致。 ```python async def execute_query_and_fetch_results(cursor): query = "SELECT * FROM some_table" await cursor.execute(query) # 需要await关键字确保异步操作被执行完毕 rows = [] while True: row = await cursor.fetchone() if not row: break rows.append(row) return rows ``` 对于上述情形,在编写代码的时候要注意所有的异步方法都需要加上 `await` 来保证它们能够按顺序运行,并且确认已经调用了适当的结果提取函数如 `fetchone()` 或者 `fetchall()` 等. #### 游标关闭不及时导致资源泄露 在长时间运行的应用程序里如果不小心遗漏了对游标的显式关闭,则可能导致内存泄漏或者其他形式的资源浪费现象发生。 ```python async with (await connection.cursor()) as cursor: await cursor.execute('...') result = await cursor.fetchall() # 使用上下文管理器自动处理游标的打开和关闭过程 ``` 通过使用Python 的上下文管理器(`with`)语法结构可以帮助简化这一流程,从而减少因疏忽而造成的潜在风险.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值