How to Regenerate Thumbnails via SSH and WP-CLI – Full Guide

⏲️ Estimated reading time: 7 min

📝 How to Regenerate WordPress Thumbnails via SSH and WP-CLI – Full Guide with Screen for Long Processes

Managing thousands of images in WordPress can overwhelm plugins and lead to server crashes. Learn how to regenerate thumbnails professionally using SSH and WP-CLI, handle long tasks with screen, prevent errors, and boost Google PageSpeed scores with optimized images.


Regenerate Thumbnails

If you run a large WordPress site, sooner or later you’ll face the challenge of regenerating thumbnails. Every image uploaded to WordPress is automatically resized into multiple versions – for archives, featured images, widgets, and responsive views.

But when you add new image sizes with add_image_size(), the old media library doesn’t magically get those sizes. And when you redesign your theme or optimize your site for performance (e.g., switching to 270x135 thumbnails for archive cards), you need to regenerate all thumbnails.

The problem: with thousands of images, using a plugin inside the WordPress dashboard often fails. PHP execution timeouts, server overloads, and frozen processes are common.

The professional solution: SSH + WP-CLI. With command-line tools, you can regenerate thumbnails faster, safer, and more flexibly. Combined with screen, you can even let processes run in the background without keeping your terminal open.

This guide will walk you through everything step by step – from understanding why regeneration matters to mastering screen for long jobs.


Why Regenerating Thumbnails is Necessary

WordPress uses multiple image sizes:

  • thumbnail – small preview
  • medium, large – general use
  • full – original upload
  • Theme-specific sizes (featured, archive-thumb, etc.)
  • Custom sizes you add with add_image_size()

Example:

add_image_size('hz-archive-thumb', 270, 135, true);

This creates a perfectly cropped 270×135 thumbnail for archive cards. But WordPress only applies it to new uploads. Old images remain without it unless you regenerate.

Without regeneration:

  • Your site still loads larger, oversized images (hurting PageSpeed).
  • Layouts break because the right size is missing.
  • Visitors download more data than needed → slower site, higher bounce rates.

Why Plugins Fail on Large Sites

Popular plugins like Regenerate Thumbnails or Force Regenerate Thumbnails work fine for small libraries. But when you have thousands of images:

  • They run inside PHP web execution → limited by max_execution_time.
  • They rely on AJAX calls → your browser must stay open.
  • They often crash when memory is exhausted.

For VPS or dedicated environments, SSH + WP-CLI is much more reliable.


WP-CLI – The Powerful Tool

WP-CLI is WordPress’s official command-line interface. Installed on most modern VPS setups, it allows you to manage your entire site without touching the dashboard.

Check if WP-CLI works:

wp --info

You’ll see output with PHP and WordPress paths.


The Danger of Running as Root

If you run WP-CLI as root, you’ll often see:

Error: YIKES! It looks like you're running this as root...

That’s because root execution is unsafe – any WP command would have full control of the entire server.

👉 Solution: Run commands as the cPanel user (e.g., helpzone).

Example:

sudo -u helpzoneblog -i -- bash -lc 'cd /home/helpzoneblog/public_html && wp media regenerate --only-missing --yes'

Step-by-Step: Regenerating Thumbnails via SSH

1) Connect via SSH

From your computer:

ssh root@YOUR_SERVER_IP

Or from Hostinger hPanel → “Terminal”.


2) Go to Your WordPress Directory

cd /home/helpzoneblog/public_html

3) Run the Regenerate Command

Full regeneration (all sizes):

wp media regenerate --yes

Only missing sizes:

wp media regenerate --only-missing --yes

For a single attachment:

wp media regenerate 123 --yes

Handling Long Processes with screen

Here’s where many admins struggle. Regenerating thousands of images can take hours. If you close your terminal or connection drops, the process dies.

That’s why we use screen.

Install Screen

dnf install screen -y

Start a Screen Session

screen -S regen

Now you’re inside a “virtual terminal” called regen. Anything you run here continues even if you disconnect.

Run the Command

sudo -u helpzoneblog -i -- bash -lc '
cd /home/helpzoneblog/public_html &&
wp media list --format=ids | xargs -n 200 wp media regenerate --only-missing --yes
'

Why Use xargs Batches?

Instead of processing all 2534 images in one go, xargs -n 200 feeds them in batches of 200 IDs.

Benefits:

  • Prevents memory exhaustion.
  • Less risk of hitting CPU or PHP limits.
  • If it crashes, you only lose the last batch, not the entire run.
How to Regenerate Thumbnails via SSH and WP-CLI

Detaching and Reattaching Screen

  • Detach (leave it running in background):
    CTRL + A then D
  • List sessions: screen -ls
  • Reattach: screen -r regen
  • Close session when done:
    Inside screen, type exit.

Understanding WP-CLI Messages

As you run regeneration, you’ll see two types of messages:

  • Regenerated thumbnails for "Post Title" (ID 3302).
    → Success: new size created.
  • No thumbnail regeneration needed for "Post Title" (ID 14012).
    → Nothing changed (size already exists, or original image too small).

Verifying Your New Thumbnails

Count how many new 270x135 images were created:

find /home/helpzoneblog/public_html/wp-content/uploads -name "*-270x135.*" | wc -l

Inspect metadata for one image:

wp post meta get 14012 _wp_attachment_metadata | grep hz-archive-thumb -A3

You should see entries for the new size.


Flushing Caches After Regeneration

After thumbnails are ready, you must clear caches so your site serves the new images.

Flush WordPress cache:

wp cache flush

If using W3 Total Cache:

wp w3-total-cache flush

Purge Cloudflare cache:

From dashboard → “Purge Everything”.


What Happens Next?

Once regeneration and cache flushing are done:

  • Homepage and archive cards load optimized 270x135 images.
  • Google PageSpeed no longer warns “Properly size images”.
  • Total page weight drops dramatically.
  • LCP (Largest Contentful Paint) improves.

Extra Tips for Image Optimization

1) Compress WebP Further

Even WebP can be oversized. Use tools like cwebp:

cwebp -q 75 input.jpg -o output.webp

2) Use Responsive srcset and sizes

WordPress automatically adds these if you use:

the_post_thumbnail('hz-archive-thumb');

3) Automate Regeneration with Cron

Add a cron job to regenerate missing thumbnails daily:

0 3 * * * sudo -u helpzoneblog -i -- bash -lc 'cd /home/helpzoneblog/public_html && wp media regenerate --only-missing --yes'

Example Workflow (Real Case)

On a WordPress VPS with 2534 images:

  • Started regeneration via SSH.
  • Processed in 200-image batches.
  • At 2057/2534, images like “Deathstalker Scorpion” and “King Cobra” were successfully regenerated.
  • Finished with 2534/2534 → new 270x135 thumbnails available.
  • Flushed W3 Total Cache + Cloudflare.
  • Google PageSpeed warning disappeared.

Common Issues and Fixes

  • Error: running as root → Always use sudo -u USER.
  • Timeout (exit status 124) → Use screen or nohup, not cPanel terminal.
  • Images not regenerating → Original smaller than requested size. WordPress won’t upscale.
  • High CPU usage → Use batches (xargs -n 200).
  • Still seeing old images → Flush all caches (WordPress, plugin, CDN).

Why This Matters for SEO

Optimized thumbnails =

  • Faster load times (especially mobile).
  • Better Core Web Vitals (LCP, CLS).
  • Higher PageSpeed scores.
  • Improved rankings and user satisfaction.

For a content-heavy site with thousands of posts, this can mean seconds shaved off loading time and a visible bump in search traffic.


Final Thoughts

Regenerating thumbnails isn’t just about fixing image sizes – it’s about site performance, SEO, and user experience.

Using SSH and WP-CLI instead of dashboard plugins makes the process scalable, robust, and professional. And with screen, you can safely run jobs that take hours without babysitting them.

Next time you add a new add_image_size() or redesign your theme, you’ll know exactly how to handle it.


🔔 For more tutorials like this, consider subscribing to our blog.
📩 Do you have questions or suggestions? Leave a comment or contact us!

🏷️ Tags: WordPress, WP-CLI, SSH, VPS, Regenerate Thumbnails, Screen, cPanel, Hostinger, Image Optimization, PageSpeed
📢 Hashtags: #WordPress #WPCLI #VPS #Screen #ImageOptimization #Caching #Performance #PageSpeed #Cloudflare #Hosting


📌 Wrap-Up

Regenerating WordPress thumbnails the professional way means leaving the dashboard behind and embracing SSH. With WP-CLI, screen, and proper cache management, you can process thousands of images reliably, keep your site blazing fast, and please both Google and your visitors.

Report an issue (max 5 words):

We store the message, post link, time, and IP (for abuse prevention). No account required.

Want to support us? Let friends in on the secret and share your favorite post!

0 online now

Live Referrers

Photo of author

Flo

How to Regenerate Thumbnails via SSH and WP-CLI – Full Guide

Published

Update

Welcome to HelpZone.blog, your go-to hub for expert insights, practical tips, and in-depth guides across technology, lifestyle, business, entertainment, and more! Our team of passionate writers and industry experts is dedicated to bringing you the latest trends, how-to tutorials, and valuable advice to enhance your daily life. Whether you're exploring WordPress tricks, gaming insights, travel hacks, or investment strategies, HelpZone is here to empower you with knowledge. Stay informed, stay inspired because learning never stops! 🚀

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.