WooCommerce: Change No. of Thumbnails per Row @ Product Gallery

WooCommerce 3.0 completely revolutionized the single product page featured and product gallery images, including their PHP. If, in the past, a simple filter from WooCommerce was enough to change the number of thumbnails per row (https://docs.woocommerce.com/document/change-number-of-thumbnails-per-row-in-product-galleries/), this does not exists anymore 🙁

So, let’s see how we can achieve this in WooCommerce 3.0 and above. For this example we’ll use two themes – in fact some theme-specific CSS is also needed together with the PHP.

WooCommerce & 2017 Theme: change number of thumbs per row in the Product Gallery

PHP Snippet: Change No. of Thumbnails per Row @ Product Gallery | WooCommerce

 * @snippet       Change No. of Thumbnails per Row @ Product Gallery
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 5.0
 * @donate $9     https://businessbloomer.com/bloomer-armada/

add_filter( 'woocommerce_single_product_image_gallery_classes', 'bbloomer_5_columns_product_gallery' );

function bbloomer_5_columns_product_gallery( $wrapper_classes ) {
   $columns = 5; // change this to 2, 3, 5, etc. Default is 4.
   $wrapper_classes[2] = 'woocommerce-product-gallery--columns-' . absint( $columns );
   return $wrapper_classes;

Unfortunately this filter is usually not sufficient as WordPress themes apply their own CSS to the new Product Gallery. So, let’s see what else is needed to make it all work.

CSS to be added for TwentySeventeen Theme (Change No. of Thumbnails per Row @ Product Gallery)

Please note: this blog’s featured image is the result of PHP + CSS on the TwentySeventeen Theme.

/* Remove default "clear" at position 5, 9, etc. This is for 4 columns */

.woocommerce-product-gallery .flex-control-thumbs li:nth-child(4n+1) {
    clear: none;

/* Add new "clear" at position 6, 11, etc. This is for 5 columns */

.woocommerce-product-gallery .flex-control-thumbs li:nth-child(5n+1) {
    clear: left;

CSS to be added for Storefront Theme (Change No. of Thumbnails per Row @ Product Gallery)

/* Add new CSS for 5 columns */

.single-product div.product .woocommerce-product-gallery.woocommerce-product-gallery--columns-5 .flex-control-thumbs li {
    width: 11.1%;
    margin-right: 11.1%;
float: left;

.single-product div.product .woocommerce-product-gallery.woocommerce-product-gallery--columns-5 .flex-control-thumbs li:nth-child(5n) {
    margin-right: 0;

Final result:

Change WooCommerce Product Gallery to 5 Columns on Storefront Theme
Was this article helpful?

Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

15 thoughts on “WooCommerce: Change No. of Thumbnails per Row @ Product Gallery

  1. Hi there,

    the code work well on desktop / tablet but not for mobile devices.
    I set 5 column but on mobile i still have 4 columns.

    Can you help me?

    1. Hi there, it must be your theme or a different plugin interfering with that. It will require custom troubleshooting. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hello, I just fixed that Firefox width issue by overwriting the minified jquery file from woocommerce/assets/js/flexslider/jquery.flexslider.min.js

    I changed this : `m.isFirefox&&(m.w=m.width())`
    To this : `m.isFirefox&&(m.w=m.viewport())`

    It will use the width of the **viewport** in place of the entire slider.

    Wish this can help! Its worked perfectly for me as i use the thumbmails on left side.

  3. Thank you! This helped me with a very quick fix to remove the line breaks with images. Much appreciated.

  4. Hi Rodolfo, excellent tip.

    Another way it’s to hook before woocommerce_single_product_image_gallery_classes and return the number of columns that also generate the correct data-columns number in the div (with the correct class); something like this works fine:

     * Change Single product photo gallery number of columns.
    	function() {
    		return 7;
      1. I just wanted to drop in and say thank you, Carlos!

  5. I need 10 columns.. how should i adjust it? thanks

    1. Hi Dale, you would put 10 instead of 5, and then based on your theme you may also need some additional custom CSS

  6. In Customizr Pro You only have to change CSS without adding any changes to functions.php:

    /* remove clear for every 4th image */
    .woocommerce div.product .woocommerce-product-gallery--columns-4 .flex-control-thumbs li:nth-child(4n+1) {
    clear: none;
    /* add clear for every 6th image (change for yourself) */ 
    .woocommerce div.product .woocommerce-product-gallery--columns-4 .flex-control-thumbs li:nth-child(6n+1) {
    clear: left;
    /* Resize image, for default is 25%, for 5 is 20%, for 6 is 16.666%, etc. */
    .woocommerce div.product div.images .flex-control-thumbs li {
    width: 16.666%;
    1. Cool, but you will also need to add responsive CSS right? 🙂

  7. snippet did not work for me, using Genesis Frameworks theme. My client has 1 product with only 2 thumbs that she wants centered under the main photo, I was hoping this would help but no changes are seen.

    1. Thanks for your comment Jan! I guess Genesis has its own code so the snippet would need to be modified slightly 🙂

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published. Required fields are marked *