Hello everyone, I am Leifeng Ge. Today, I will introduce some methods for optimizing WordPress Admin Dashboard image uploads. Previously, when uploading images in the WordPress Admin Dashboard, I sometimes encountered errors, especially when uploading multiple images at once, which could easily cause high database load. Below, I will explain how to optimize WordPress image upload speed and reduce database queries.
Do not name uploaded WordPress images as 1, as it will increase database queries:
Some people are too lazy to name images properly and just use something like 1.jpg. When uploading such an image in the WordPress Admin Dashboard, WordPress will check if 1.jpg already exists, then automatically rename it to 1-2.jpg. If 1-2.jpg also exists, it continues to rename automatically, looping endlessly, putting immense pressure on database queries. If you are truly lazy, you can refer to the method below.
WordPress Chinese Image Name Auto-Renaming / Reduce SQL Queries:
Scenario 1: If you are using a Windows server, uploading images with Chinese names will result in an error, prompting
„An error occurred during upload. Please try again later.“Although you can use a Plugin to automatically convert names to Pinyin/English, this can affect upload performance. Here, using a piece of code to automatically rename images upon upload will suffice. Scenario 2: Too many duplicate image names are uploaded to WordPress. WordPress needs to query the database and then rename the images. With too many images, this could even cause the database to crash. The solution is simple: add the following code to functions.php:
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
function custom_upload_filter( $file ){
$info = pathinfo($file['name']);
$ext = $info['extension'];
$filedate = date('YmdHis').rand(10,99);
$file['name'] = $filedate.'.'.$ext;
return $file;
}The principle is to rename the image based on the upload time, for example: 2019092010182810.jpeg If you don't know how to add code, you can refer to:
Safe method to add code to the functions.php file: Code SnippetsOf course, you can also directly use this Plugin:
WordPress Image Auto-Rename Plugin Unique Rename Image File UploadWordPress Upload JPG Format Image Auto-Compression:
Compressing images can save Traffic and speed up website loading. WordPress provides a default image compression function. We can set the compression ratio. Note that it only supports JPEG format images. Add the following code to functions.php:
add_filter( 'jpeg_quality', create_function( '', 'return 90;' ) );
The number 90 in the code is the compression ratio. Adjust the compression ratio according to your needs. For other image compression needs, you can use the 「
EWWW Image Optimizer「 Plugin, which supports JPG, PNG, and even GIF. It also provides the function to convert image formats during compression, such as converting to WebP format, and converting between JPG and PNG.

There are many similar image compression Plugins. You can choose one that you find convenient to install and use.
Reduce WordPress Uploaded Image Thumbnails:
When WordPress uploads an image, it automatically generates 3 sizes of thumbnails. For Shared Hosting / low-memory VPS, this can more or less affect performance. We can disable this or only generate one size of thumbnail. In the WordPress Admin Dashboard Settings → Media → Image sizes, set the thumbnail size you don't need to generate to 0.

If you really don't need thumbnails, then disable them completely. Add the following code to functions.php:
//彻底禁止WordPress缩略图
add_filter( 'add_image_size', create_function( '', 'return 1;' ) );
Related articles:
Disable WordPress 5.2.1 Automatic Thumbnail Cropping FunctionClean Up Unused WordPress Thumbnails:
As mentioned above, disabling thumbnails. However, previously generated thumbnail images take up a lot of space. Manually cleaning them up would be a nightmare. Let「s use a Plugin. 」
Delete not used image「 is a Plugin that can automatically search for unused thumbnails. 1. Before using Delete not used image, it will prompt you to back up first (it is recommended to back up first). In 」options「, you can back up via Backup system / Create backup folder, or you can back up using other methods. 2. In 」options「 under _ Show, set original, then directly click . This ensures the original image is not lost. 3. Click 」Images「 to start searching for thumbnail images, then 」Delete all「 to delete them all.

If you have too many thumbnail files, it may take a long time, staying in the "Fetching server…" state. Please wait patiently. Through the optimization settings above, you will find that uploading images in the Admin Dashboard is much faster. Now you can start uploading images with confidence, without worrying about the database crashing due to excessive queries.
Other related articles: What to Do If Website Images Load Slowly_3 Methods for Website Image Acceleration Methods for Counting WordPress Website Images, Formats, and Sizes Modify WordPress Website Login Interface LOGO and Images Without Code WordPress automatically adds ALT and title names to images
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.