How to Regenerate Images after Changing their Sizes or Changing a Theme
Table of Contents
Perhaps you know the situation when after changing add_image_size()
parameters or after changing your website theme WordPress does not generate image sizes automatically and images with old resolutions are still displayed on the site.
What should you do in this situation? If there are only 2-3 pictures in your uploads folder, you can simply reupload them. But what to do if there are 2-3 thousands of images?
There is two ways to solve this situation – with plugins and with code:
Regenerate Thumbnails with Plugins
Ok, I can recommend you two simple plugins:
- Ajax Thumbnail Rebuild
- Force Regenerate Thumbnail
Each of them has its own advantages and disadvantages, so maybe for different situations you can choose what plugin more fits for you.
Regenerate Thumbnails Programmatically
Here I just want to show you the code which allows to regenerate images, how you will use it – it is your choice.
$attachment_id = 5; // pass your attachment ID here $path = get_attached_file( $attachment_id ); $meta = wp_generate_attachment_metadata( $attachment_id, $path ); wp_update_attachment_metadata( $attachment_id, $meta );