1007Regenerating Thumbnails in WordPress

Option 1: Plugin

The Regenerate Thumbnails Plug-in.

This option is usualy slower - and some hosting providers might confuse it for a malicious attach and block the IP.

Option 2: WP-CLI

WP-CLI is the command line interface for WordPress/ClassicPress.

Installation

From the WP-CLI Guide

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Run --info from your WP root directory, to check if it works:

php wp-cli.phar --info

If you get a json_encode error, it means your PHP version is not compatible with WP-CLI.

PHP 7 was the default on one server, it did not work.

Check for other PHP versions
which php
// /usr/bin/php

ls /usr/bin/php* 
// php80 php81 php82 php83

Let's use the latest verson of PHP.

php83 wp-cli.phar --info

Regenerating

Regenerate all images, without confirmation.

php83 wp-cli.phar media regenerate --yes

Regenerate thumbnails only.

$ php83 wp-cli.phar media regenerate --image_size=thumbnail

More options for regenerating images with WP-CLI:

# Regenerate thumbnails for given attachment IDs.
php83 wp-cli.phar media regenerate 123 124 125

# Re-generate all thumbnails that have IDs between 100 and 200.
seq 100 200 | xargs php83 wp-cli.phar media regenerate

# Re-generate all thumbnails that have IDs between 100 and 200.
seq 100 200 | xargs php83 wp-cli.phar media regenerate

# Re-generate all thumbnails that have IDs between 100 and 200, only thumbnails
seq 100 200 | xargs php83 wp-cli.phar media regenerate --image_size=thumbnail

#### Error

`Error: Error establishing a database connection.`

When working on _localhost_, use `127.0.0.1` instead of `localhost` in wp.config
```php
define( 'DB_HOST', '127.0.0.1' );