jakson-wordpress-development-and-courses

Controlling Image Sizes for faster WordPress sites: The Nuclear Option!

Hello, WordPress enthusiasts! In today’s article, we are tackling a persistent problem faced by developers and content creators alike: managing the size of images being uploaded to your WordPress site.

In the contemporary digital world, where even a modest camera or phone can generate large, high-quality images, keeping image sizes in check becomes a pressing issue. Despite your best efforts to remind your clients, teammates, or friends to upload smaller images, huge image files somehow find their way to your site.

Of course, numerous plugins can compress images upon upload and impose size restrictions. However, these plugins, while certainly useful, start compressing from the original size. That means if your image file is five megabytes, compression will reduce the size, but it may still be larger than ideal.

Starting Small

In my opinion, the optimal solution for image-heavy blogs and similar sites begins with uploading smaller images. If your initial image file is small, then your compression plugin or Content Delivery Network (CDN) starts with a more manageable task. Remember, the compression tool is compressing what’s there, so a smaller starting point will lead to a smaller end result.

User Education

A crucial part of this strategy is educating your users on how to generate suitably sized images. There are two key steps to this process.

  1. Resize: Have your users resize the image using the tools available on their desktop, whether a Mac or a PC. The resized image should be 1600 pixels or less in width, or at most 1920 pixels. Most of the time, even wide desktop viewports won’t display more than this amount of pixels.
  2. Compress: Once resized, ask users to upload the image to a compression site like tinypng.com to reduce the size further. While Tinypng does offer a WordPress plugin, training users to upload already small images gives your compression plugins and CDNs a head start.

Taking Control: The Nuclear Option

To ensure image sizes are kept in check, we can employ a ‘nuclear option’: altering the media upload limit.

To demonstrate this, let’s delve into an example. Suppose you have a site where the maximum file upload is set to an extravagant 256 megabytes. This can be reduced drastically to enforce smaller image uploads.

The first step is to locate a suitable plugin to add custom functions. For this example, we’ll use a custom plugin which we can edit within the WordPress admin.

Having activated our plugin, we can now look at the code. The key is to add a piece of code that will reduce the maximum allowable file size for uploads.

When implemented correctly, this code will limit the size of uploaded media files. In our case, we reduced the maximum file size from 256 megabytes to a much more manageable 244 kilobytes. As a result, any image, even a well-compressed JPEG, must fit within this limit to be uploaded to your site.

Remember, it is always advisable to edit using FTP, take backups, and avoid editing on live sites. The method discussed here works best on demo sites and is for illustration purposes.

While this is indeed the nuclear option, it’s worth considering, especially for sites with heavy image content. In a future article, we will explore image compression plugins in more detail, conduct speed tests, and compare different strategies.

As always, I look forward to hearing your thoughts and engaging in productive debates on this subject. Until next time, happy WordPressing!