How to Change Product Category Thumbnail Size in WooCommerce

Quick Summary

  • Swap wp_get_attachment_thumb_url(), which always returns the small thumbnail, for wp_get_attachment_image_src(), which takes the image size as its second argument.
  • Pass full for the original upload or any registered size such as medium, large or woocommerce_thumbnail, and regenerate thumbnails for new custom sizes.
  • Check $thumb before printing, because a category without an image returns false, and swap deprecated get_woocommerce_term_meta() for get_term_meta().

The earlier snippet for listing WooCommerce product categories with images uses wp_get_attachment_thumb_url(), which always returns the small thumbnail size. To choose the category thumbnail size yourself, swap it for wp_get_attachment_image_src(), which takes the image size as its second argument. Below is the modified version of Display WooCommerce Categories With Thumbnails.

As before, add the code to the theme template (in your child theme) where the category list should appear, inside a <ul> element, since it outputs <li> items.

PHP
<?php
    $prod_categories = get_terms( 'product_cat', array(
        'orderby'    => 'name',
        'order'      => 'ASC',
        'hide_empty' => 1
    ));
    foreach( $prod_categories as $prod_cat ) :
        $cat_thumb_id = get_woocommerce_term_meta( $prod_cat->term_id, 'thumbnail_id', true );
        $thumb = wp_get_attachment_image_src($cat_thumb_id, 'full');
?>

<li>
    <a href="<?php echo get_category_link( $prod_cat->term_id ); ?>">
        <img src="<?php echo $thumb[0]; ?>" alt="<?php echo $prod_cat->name; ?>" />
    </a>
</li>

<?php endforeach; wp_reset_query(); ?>

How to pick the size

  • wp_get_attachment_image_src( $cat_thumb_id, 'full' ) returns an array with the image URL, width and height. $thumb[0] holds the URL.
  • 'full' is the original uploaded image. Replace it with any registered size name: WordPress’s 'thumbnail', 'medium' or 'large', WooCommerce’s 'woocommerce_thumbnail', or a custom size you added with add_image_size().
  • WordPress creates image sizes when an image is uploaded. If you register a new custom size, older category images only get it after you regenerate their thumbnails.

Things to watch

  • If a category has no image, wp_get_attachment_image_src() returns false and $thumb[0] triggers a PHP warning, so check $thumb before printing it.
  • get_woocommerce_term_meta() is deprecated in current WooCommerce; get_term_meta() with the same arguments returns the same value.
  • Wrap the URLs in esc_url() and the category name in esc_attr() for safer output.

For shop and category pages designed with the image sizes they need, see my WooCommerce development services.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More