Home • Blog • Article

How to Change the Product Gallery Thumbnail Size in WooCommerce

By Fathima Nourin TM • •
, ,

Problem Statement & Impact on E-Commerce Architecture

In WooCommerce deployments, managing product image assets directly dictates the HTTP payload size, Time to First Byte (TTFB), Largest Contentful Paint (LCP), and database input/output (I/O) efficiency. When an e-commerce platform relies on default image sizing configurations, it frequently introduces architectural bottlenecks. The core technical challenge revolves around how the WordPress media library and WooCommerce handle intermediate image sizes (specifically product gallery thumbnails, single product images, and catalog grids).

By default, WordPress crops and scales images based on global settings defined within the database options table. If these dimensions are ill-fitted to the active theme’s CSS flexbox or CSS Grid layouts, browsers are forced to scale images dynamically via HTML attributes ($width$ and $height$) or CSS rules. This forces the client to download a high-resolution asset and downscale it in the DOM, directly degrading mobile performance metrics and compounding core web vitals failure rates.

Furthermore, misconfigured gallery thumbnail sizes affect server performance. If a catalog page lists 24 products, and each product renders 4 gallery thumbnails alongside a primary image, the browser must issue over 120 HTTP requests for image payloads alone unless lazy loading and HTTP/2 or HTTP/3 multiplexing are heavily optimized. Storing unoptimized, incorrectly cropped thumbnail sizes bloats the file system inode count and consumes excessive disk space on the hosting server, eventually causing backup failures, prolonged database queries during media attachment lookups, and heightened susceptibility to resource exhaustion under traffic spikes.

🚨 Facing an active site error or malware warning?

Chat with an engineer on WhatsApp within 15 minutes.

💬 Chat on WhatsApp

Root Cause Analysis & Database Mechanics

To understand why changing product gallery thumbnail sizes requires more than simply updating a UI toggle, one must examine the underlying execution path. WooCommerce relies on WordPress’s native image manipulation engine—specifically the image_make_intermediate_size() function executed via the GD Library or ImageMagick PHP extensions.

When an administrator uploads a source image (e.g., 2000×2000 pixels at 2MB), WordPress stores this master file in the wp_posts and wp_postmeta tables. It then generates derivative files based on registered image sizes. These are stored in the filesystem under wp-content/uploads/YYYY/MM/, and their metadata is serialized inside the _wp_attachment_metadata meta key.

The WooCommerce product gallery relies on specific size registrations, historically initialized via theme support or WooCommerce settings:

add_image_size( 'woocommerce_gallery_thumbnail', 100, 100, true );

When you alter the thumbnail size via the WordPress Customizer or code hooks, the database entry for shop_thumbnail_image_size updates, but existing attachments retain their old physical files and metadata arrays. Consequently, the frontend HTML output references the new CSS dimensions, but the HTML <img> tag points to old image URIs or forces the browser to scale an image that was generated using the legacy aspect ratio and pixel dimensions.

This mismatch forces CPU cycles on the client side, triggers layout shifts (Cumulative Layout Shift – CLS), and causes visual distortion if hard cropping (true parameter) was disabled or modified after initial uploads.

Step-by-Step Implementation & Remediation Guide

Modifying product gallery thumbnail sizes requires a systematic approach encompassing configuration updates, database synchronization, and batch image regeneration. Relying solely on the graphical user interface often leaves behind orphaned thumbnail files or unscaled legacy assets.

Method 1: Programmatic Configuration via Functions.php or Custom Plugin

For headless, enterprise, or version-controlled WooCommerce setups, hardcoding image dimensions via hooks ensures consistency across staging and production environments. Add the following code snippet to your child theme’s functions.php file or a custom functionality plugin:

/**
 * Update WooCommerce product gallery thumbnail dimensions programmatically.
 */
function sitesuraksha_update_woocommerce_image_dimensions( $size ) {
    // Define exact width, height, and hard crop status
    $size['width']  = 150;
    $size['height'] = 150;
    $size['crop']   = 1; // 1 = hard crop, 0 = soft proportional resize
    return $size;
}
filter_related_image_size_overrides = true; // Modern WP safeguard
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', 'sitesuraksha_update_woocommerce_image_dimensions' );

Method 2: Updating via WP-CLI (Recommended for Production)

Using WP-CLI bypasses browser timeout limits and memory exhaustion issues common in large e-commerce catalogs. Execute the following commands via Secure Shell (SSH) on your server.

  1. Update the core database options for WooCommerce thumbnail width, height, and cropping:
    wp option update shop_thumbnail_image_size '{"width":150,"height":150,"crop":1}'
  2. Verify the option update was successfully written to the database:
    wp option get shop_thumbnail_image_size
  3. Regenerate all image thumbnails to force the server to cut new assets based on the updated dimensions. Install and run the regeneration package:
    wp media regenerate --yes

    Note: If you only want to regenerate specific attachment IDs or avoid processing full-size source images, use a dedicated thumbnail regeneration plugin compatible with WP-CLI, such as wp media regenerate --image_sizes=woocommerce_gallery_thumbnail.

Method 3: Customizing via the WordPress Customizer Interface

For standard administrative workflows without CLI access, follow these precise execution steps:

  1. Navigate to your browser and log into the administrative backend at https://yourdomain.com/wp-admin.
  2. In the left-hand administrative navigation menu, select Appearance > Customize.
  3. Locate and click on the WooCommerce panel within the customizer sidebar.
  4. Select the Product Images subsection.
  5. Locate the input fields designated for Thumbnail width and Thumbnail height. Input your target pixel values (e.g., width: 150, height: 150).
  6. Ensure the hard crop checkbox matches your design requirements. Leaving it unchecked maintains original aspect ratios, which can lead to misaligned grid layouts if product images have mixed orientations (portrait vs. landscape).
  7. Click Publish to write the configuration to the wp_options table.

Production Hardening & Edge Cases

Executing image size modifications on live production servers introduces specific architectural risks, including database lockups, HTTP 504 Gateway Timeouts, and storage exhaustion.

Storage Overhead: Generating a new thumbnail size for 10,000 products with an average of 4 gallery images each results in 40,000 new files written to disk. Ensure your hosting volume has at least 2x the current wp-content/uploads directory size available in free inodes and disk space before running regeneration scripts.

Object Caching Conflicts: If you run Redis or Memcached on your WordPress stack, image metadata queries and WooCommerce transient caches may serve stale asset URLs post-regeneration. Always flush object caches and CDN edge caches immediately after updating image sizes:

wp cache flush

CDN and Lazy Loading Integration: Third-party Content Delivery Networks (like Cloudflare or CloudFront) cache static assets based on URI paths and query strings. If your thumbnail filenames do not change during regeneration, the CDN may serve old, incorrectly scaled images. Purge your CDN cache entirely:

# Example for invalidating CDN cache via API or CLI wrapper
wp cloudflare cache purge

Theme CSS Overrides: Many commercial WooCommerce themes inject hardcoded inline CSS or overriding stylesheet rules for gallery thumbnails (e.g., forcing max-width: 100px). Inspect your single product page DOM using browser developer tools to verify that CSS rules do not conflict with your new pixel dimensions, preventing blurry downscaling or stretched layouts.

Diagnostic Verification & Checklist

Post-implementation validation ensures that your WooCommerce gallery thumbnails render correctly across devices, load efficiently, and pass core web vitals audits. Use the verification matrix below to confirm system stability.

Verification Check Target Metric / Expected Result Diagnostic Tool / Command
Database Option Integrity JSON array reflects exact target width and height. wp option get shop_thumbnail_image_size
Filesystem Asset Generation New thumbnail files exist in wp-content/uploads/ with matching dimensions. SSH / find . -name "*150x150*"
DOM Image Inspection HTML <img> tags load the correct resized asset without CSS downscaling. Browser DevTools (Elements Tab)
HTTP Status Validation All thumbnail URIs return HTTP 200 OK without broken links (404). curl -I https://yourdomain.com/path-to-image.jpg
Page Load Performance No increase in total page weight; LCP remains under 2.5 seconds. Google PageSpeed Insights / Lighthouse CLI
  • Verify that responsive image srcset attributes correctly serve smaller thumbnail variants to mobile viewports.
  • Check error logs (wp-content/debug.log or server error logs) to ensure no PHP memory limit errors occurred during the regeneration process.
  • Confirm that image file permissions remain secure (644 for files, 755 for directories) across all newly generated thumbnail assets.

Professional WordPress Support & Care

Maintaining a high-performing, secure WordPress site requires continuous monitoring and proactive updates. At SiteSuraksha, our dedicated technical team provides 24/7 security hardening, speed optimization, and hands-on maintenance so you can focus on growing your business.

Follow SiteSuraksha on Google
Add us to your preferred sources for verified WordPress & hosting guides.
FREE 30-SECOND DIAGNOSTIC

Is Your Website Fast & Secure?

Run an instant scan for security vulnerabilities, bloated plugins, and TTFB latency.

🔍 Test Your Site Now →
Map Your Issue to Guaranteed IT Care
Security & Malware
Hacks, 0-day exploits & backup failures
Pro Care (₹5,420/mo) →
Speed & Cloud Bills
Slow checkout, high TTFB & cloud waste
Pro Care (₹5,420/mo) →
ERP & Automation
GST pipelines, RPA & AI support agents
Enterprise (₹14,999/mo) →
EXPERT WORDPRESS CARE

Need Help Securing or Speeding Up Your Site?

Get 24/7 proactive security WAF, daily cloud backups, and sub-second speed optimization from ₹3,470/mo.

💬 Chat on WhatsApp Explore Plans
← Back to All Articles