WordPress GuideWP-CLI → Regenerating Images

Regenerating WordPress images with WP-CL

Your guide to bare metal management best practices.

The WordPress Media Library is where you can add media assets to your site. If you are editing a post, page, or product and adding a featured image, the image will automatically be added to the site’s media library. WordPress will accept several kinds of image formats, document file formats, and video formats.

Ideally, if you are planning on trying to upload a large MP4 video file on the site, then the recommendation would be to first optimize the video file.

If possible, use a video hosting service such as YouTube or Vimeo, after which you could embed the video on the page or post on your site using the “embed HTML code” provided by the video hosting service. WordPress, by default, accepts many file formats that can be uploaded to the media library.

Those file formats are covered in the section below.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

WordPress image file types

Here are the image file types that WordPress supports:

WordPress document file types

Here are the document file types that WordPress supports:

WordPress audio file types

Here are the audio file types that WordPress supports:

WordPress video file types

Here are the video file types that WordPress supports:  

Adding media images using media > Add new

To add media images to your site from the wp-admin area, navigate to the Media > Add New option. Then, select the file you want to upload.

The application will return the following status message to show that the file has been uploaded correctly on your site:

Viewing media images using Media > Library

To view images already in the site’s media library from the wp-admin area, go to the Media > Library option. Here you can upload new files and manage existing media in the library:

WordPress will store images being used on the site in the Media Library, which will use a database reference and upload the file to the Uploads folder on the site’s server.

If you are just getting started with WordPress, then the default image sizes that WordPress would be using are as follow:

WP media folder

WordPress by default stores images in the following folder on your site’s server:

wp-content/uploads

Changing the upload folder location is possible by adding a constant to your site’s wp-config.php file. The following is an example of constant change with regard the Uploads folder to use:

define( ‘UPLOADS’, ‘blog/wp-content/uploads’ );

Why would you need to regenerate images?

The most common reason you would need to regenerate your image thumbnails for your media library on your site would be to add custom image sizes or change the image sizes in your theme for your WooCommerce Store.

Another reason why you would need to regenerate thumbnail images will be if a plugin you are using on the site adds new image sizes, such as a gallery plugin.

WP-CLI (WordPress Command Line Interface) media regeneration

WP-CLI makes it easier to regenerate thumbnails without having to install a thumbnail regeneration plugin on your site.

If you have other WordPress-specific questions, then the Liquid Web Knowledge Base has you covered.

To regenerate thumbnails, specify attachment IDs (replacing the actual IDs needed), and then use this WP-CLI command:

wp media regenerate 123 124 125

To be able to regenerate all thumbnails for images without confirmation, use this WP-CLI command:

wp media regenerate –yes

To regenerate all thumbnails that have an ID between 1000 and 2000, then use this WP-CLI command:

seq 1000 2000 | xargs wp media regenerate

To be able to only regenerate thumbnails for images with missing image sizes.

wp media regenerate –only-missing

To regenerate the thumbnails for all images of the ‘large’ image size only, use this WP-CLI command:

wp media regenerate –image_size=large

To keep the existing thumbnails which would be by default deleted when they are regenerated then use this WP-CLI command:

wp media regenerate –skip-delete

Regenerating images will help resolve having images not displaying correctly when you change themes or plugins on your site.

Disabling background image generation in WooCommerce

If you are using WooCommerce on your site, since WooCommerce Version 3.3 it includes a background image generation feature that will run if you change themes on your site.

To ensure that the background image generation feature in WooCommerce does not run on your site, you can use this code snippet since you will be regenerating images using a WP-CLI command.

add_filter( ‘woocommerce_background_image_regeneration’, ‘__return_false’ );

WordPress image FAQs

What are the best image sizes for WordPress?

How do you enhance the image quality in WordPress?

Additional resources

What is WordPress? →

A complete beginner’s guide—from use cases, to basics, to how to get started

WordPress database search: WP DB search with WP-CLI →

Learn how to use WP-CLI to search and replace data in your WordPress database efficiently.





How to integrate WordPress and Slack →

If your org uses Slack and WordPress, there are several ways you can tie them together.

Luke Cavanagh

Luke Cavanagh, Strategic Support & Accelerant at Liquid Web, is one of the company’s most seasoned subject matter experts, focusing on web hosting, digital marketing, and ecommerce. He is dedicated to educating readers on the latest trends and advancements in technology and digital infrastructure.