Streamlining image sizes

Hello guys,

Working on some cleaning up here and I’d like to establish a more comprehensive approach to our image sizes as we now have 16 different sizes registered and we hardly use that much.

We have…

  • Original image (WP)
  • Thumbnail - (150x150) (WP)
  • Medium - (300x300) (WP)
  • Large - (1024x1024) (WP)
  • nh-medium - (500x500) (Custom)
  • entry - (1184x9999) (Pro)
  • entry-cropped - (1184x662) (Pro)
  • entry-fullwidth - (1184x9999) (Pro)
  • entry-cropped-fullwidth - (1184x662) (Pro)
  • woocommerce_thumbnail - (300x300) (WooCommerce)
  • woocommerce_single - (600x0) (WooCommerce)
  • woocommerce_gallery_thumbnail - (100x100) (WooCommerce)
  • shop_catalog - (300x300) (Pro)
  • shop_single - (600x0) (Pro)
  • shop_thumbnail - (100x100) (Pro)
  • wc_order_status_icon - (32x32) (WooCommerce Plugin)
  • post-thumbnail - (100x100) (Pro?)Not reported in Toolset but displayed in TinyPNG sizes

Remark #1: The WooCommerce image size name has changed and now uses “woocommerce_” prefix instead of “shop_”. I’m not sure if this is how X overwrite WooCommerce’s image sizes but I believe X should be using the same image size name. Has this already been addressed in the coming release candidate?

Reference: https://iconicwp.com/blog/manage-woocommerce-product-image-sizes-3-3/#comment-273


Remark #2: Something odd seems to be happening with the “woocommerce_single” / “shop_single” sizes as their height returns 0. Is this expected?

This list was pulled from Toolset when building a query and requesting the post featured image as you can select which image size to use. TinyPNG also report a height of “?


Remark #3: We have tried to overwrite X logic for the image size without luck. Our blog posts have been heavily customized. We always use a fullwidth layout for blog posts and the featured image height is fixed. We’d like to remove unused image sizes and use a fixed image size (without the padding logic applied).

A) Can we safely remove “entry” and “entry-cropped”? Should these be used anywhere, will it automatically fallback on “entry-fullwidth-cropped” or another existing image size? We only wish to use “entry-fullwidth-cropped”.

B) I tried to remove the sizes we don’t use but I’m not sure if it’s working. Toolset still displays the sizes after I add the following code in our child-theme functions.php:

// Add custom image size
if ( function_exists( 'add_image_size' ) ) {
	add_image_size('nh-medium', 500, 500);
	//add_image_size('entry', 0);
	//add_image_size('entry-cropped', 0);
	add_image_size('entry-fullwidth',			1200, 9999,false);
	add_image_size('entry-cropped-fullwidth',	1200, 630, true);
}

if ( function_exists( 'remove_image_size' ) ) {
	remove_image_size('entry');
	remove_image_size('entry-cropped');
	remove_image_size('wc_order_status_icon');
}

function nh_filter_image_sizes( $sizes) {
	unset( $sizes['entry']);
	unset( $sizes['entry-cropped']);
	unset( $sizes['wc_order_status_icon']);
	return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'nh_filter_image_sizes');

The commented out lines is something I tried after reading this: Change theme featured images and thumbnail sizes


Remark #4: I used to restore the WooCommerce image size settings using this snippet:

add_filter('init', 'remove_product_settings_filter');
function remove_product_settings_filter() {
    remove_filter('woocommerce_product_settings', 'x_woocommerce_remove_plugin_settings');
}

It looks like this doesn’t work anymore, could you let me know how to update it?


Remark #5: The image size “post-thumbnail” doesn’t look like a standard image size (see the_post_thumbnail()). If this is indeed added by Pro, can you confirm we can simply replace it with a new size as such?

add_image_size('post-thumbnail', 150, 150, true);


Remark #6: As you can see in the snippet provided in Note #3, I have tried to change the “entry-cropped-fullwidth” image size to 1200x630 but it didn’t change anything. How can we replace that?

Thank you!

Hi @thisisbbc,

###Remark 1:
We previously were changing the original Woocommerce image sizes in both X and Pro themes. But after the introduction of the Woocommerce version 3.X, the system has changed, and it was not sustainable to override the images. That is why we changed the behavior. Now, we do not touch the Woocommerce image sizes anymore, so you do not have any changes from our part to whatever you want to achieve image-wise.

###Remark 2:
I personally did not encounter such a problem. Anyway, this does not seem to be our theme issue; you can test that by changing our theme to another one and do the test.

###Remark 3:
I am not sure what you mean by padding logic. If you check our demo page here:
http://demo.theme.co/integrity-1/5-reasons-you-need-the-x-theme/

You will see that the theme uses the standard WordPress image system. You need to be more specific about what you want to achieve.
A) The entry-fullwidth-cropped image size is used whenever the layout of the page is set to be fullwidth. So you need to go to Pro > Theme Options > Layout and set everything to Fullwidth.

It is possible to override the functionality but it is a huge amount of the customization and outside of our support scope. The image sizes are set as functions in the files below:

wp-content/themes/pro/framework/functions/thumbnails.php
wp-content/themes/pro/framework/functions/frontend/featured.php

The way that you can override the functions are to copy the whole function into the functions.php file of your Child Theme. Then you can do the changes as you wish there.

B) You need to copy the functions of our theme which I mentioned and do the changes there. That will 100% change the theme image sizes. But I am not sure about the Toolset plugin. You need to ask the support of that plugin for more information.

###Remark 4:
As mentioned above we do not override the Woocommerce plugin image sizes anymore. Please make sure that you update the theme to the latest version and then you can use whatever standard Woocommerce has to override and change the images.

You can learn more about the case here.

###Remark 5
We set the post-thumbnail image size in the file below:

wp-content/themes/pro/framework/functions/thumbnails.php

If you want to remove those sizes and add new ones you will need to add the code below to functions.php file of your Child Theme:

// Remove X Image Sizes
// =============================================================================
add_action('wp', 'remove_x_image_sizes');
function remove_x_image_sizes() {
  remove_image_size('post-thumbnails');
  remove_image_size('entry');
  remove_image_size('entry-cropped');
  remove_image_size('entry-fullwidth');
  remove_image_size('entry-cropped-fullwidth');
}
// =============================================================================

###Remark 6:
You need to remove those sizes first and then add them again. Check the code above to know how to remove them.

Thank you.

Hello Christopher,

Thanks for the detailed reply!

Remark #1: Gotcha!

FYI – In my research I found that WooCommerce currently register both image size names using “shop_” and “woocommerce_” for backward compatibility. The “shop_” prefix is deprecated and will be removed in WC 4.0.


Remark #2: This seems to be happening with Twenty Nineteen too. Weird, but unrelated to X. I think it’s because there’s no hard cropping on the shop_single and woocommerce_single image.


Remark #3: The “padding logic” happens inside thumbnails.php to calculate the appropriate image size depending on each stack configuration, based on the padding and margin around the grid/featured image. What I want is to remove any calculation and use a fixed size instead.

I followed your suggestion and copied the function in our child-theme but it returned an error 500. I’m not sure why but I can’t re-declare the same function name, so I used a different one instead and I re-configured each image size and now it works fine:

add_action('after_setup_theme', 'nh_setup_thumbnails', 20);

function nh_setup_thumbnails() {
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 150, 150 , true);
	add_image_size( 'entry',                   0);
	add_image_size( 'entry-cropped',           0);
	add_image_size( 'entry-fullwidth',         1200, 9999,                                   false );
	add_image_size( 'entry-cropped-fullwidth', 1200, 630, true  );
}

FYI, the following functions have no impact, there’s no change with or without them:

add_action('wp', 'nh_remove_x_image_sizes');
add_filter('intermediate_image_sizes_advanced', 'nh_filter_image_sizes');

function nh_remove_x_image_sizes() {
    remove_image_size('entry');
    remove_image_size('entry-cropped');
}

function nh_filter_image_sizes($sizes) {
	unset( $sizes['entry']);
	unset( $sizes['entry-cropped']);
	return $sizes;
}

Remark #4-5-6: Gotcha!


Remark #7: I think X/Pro has disabled Wordpress srcset functions which was introduced with the new way to handle responsive image in WP 4.4 (Responsive Images in WP4.4).

Can you confirm this?

If X does not make use of the srcset features, which are using the default WP Medium and Large image sizes, wouldn’t it make sense to remove these too? I mean, in theory, these image sizes are not used anywhere in X, correct?

Thanks again for your help!

Hello @thisisbbc,

#2: Please do check the WooCommerce official documentation for the image sizes here:

And it is best that you may use 3rd party plugin to clean up those existing and unused images by checking out this links:

#3: This code works on my end without any issue:

add_action('after_setup_theme', 'nh_setup_thumbnails', 20);
function nh_setup_thumbnails() {
  add_theme_support( 'post-thumbnails' );
  set_post_thumbnail_size( 150, 150, true);
  add_image_size( 'entry', 0);
  add_image_size( 'entry-cropped', 0);
  add_image_size( 'entry-fullwidth', 1200, 9999,false );
  add_image_size( 'entry-cropped-fullwidth', 1200, 630, true );
}

Please be careful when copying and pasting. Windows machine tend to change the single “'” quotes to a different one which usually causes an issue.

#7: WP Medium and Large are WordPress default sizes (https://codex.wordpress.org/Post_Thumbnails#Thumbnail_Sizes)

X theme still uses srcset features especially if you have inserted the images via the default WP editor or Gutenberg. The Cornerstone’s image element on the hand do not use the srcset features.

Hope this helps.

Hello @RueNel,

Thanks for the detailed reply.

Regarding #3, the code you’ve pasted is the working code. In my previous reply, it’s the following block of code that has had no impact (with nh_remove_x_image_sizes() and nh_filter_image_sizes($sizes))

#7: You said X still uses srcset. Can you confirm this applies to the Icon stack? If yes, where? I can find no markup on the blog page, single blog post, etc. All featured images use a direct link to the entry-fullwidth image. Tested on default Pro theme.
<img width="1184" height="493" src="https://.../storage/2016/11/ribbed-cuffed-knit-beanie-1545K-flexfit-winter-cap-now-available-nationhats-1184x493.jpg" class="attachment-entry-fullwidth size-entry-fullwidth wp-post-image" alt="">

This is the output for a featured image on our blog page using Twenty Nineteen with the srcset markup:
<img width="100" height="42" src="https://.../storage/2016/11/ribbed-cuffed-knit-beanie-1545K-flexfit-winter-cap-now-available-nationhats-100x42.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" srcset="https://.../storage/2016/11/ribbed-cuffed-knit-beanie-1545K-flexfit-winter-cap-now-available-nationhats-100x42.jpg 100w, https://.../storage/2016/11/ribbed-cuffed-knit-beanie-1545K-flexfit-winter-cap-now-available-nationhats-800x333.jpg 800w, https://.../storage/2016/11/ribbed-cuffed-knit-beanie-1545K-flexfit-winter-cap-now-available-nationhats-300x125.jpg 300w, https://.../storage/2016/11/ribbed-cuffed-knit-beanie-1545K-flexfit-winter-cap-now-available-nationhats-1024x427.jpg 1024w, https://.../storage/2016/11/ribbed-cuffed-knit-beanie-1545K-flexfit-winter-cap-now-available-nationhats-1184x493.jpg 1184w" sizes="(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw">

Thank you!

Hey @thisisbbc,

X/Pro theme still uses srcset features especially if you have inserted the images via the default WP editor or Gutenberg. The Pro Editor/Cornerstone’s image element on the hand do not use the srcset features.

srcset will only be applied to images inserted in the WP editor or Gutenberg. Those image that can be found in the content of a page or post built with the default WP editor or Gutenberg. All the images in the theme particularly the featured image in the Icon stack do not have srcset in it which is why you are seeing a different image output.

Hope this explains it.

Hey @RueNel,

Thanks again for the precision.

Since we never use the classic editor or Gutenberg, is it safe to assume the vast majority of the pictures on our website will not use the srcset markup?

Also, can you give me a little bit more information about the position of Themeco regarding the srcset feature introduced in WP4.4? Is there any plan to follow this trend and bake this into Cornerstone at some point?

Thank you!

Hi @thisisbbc,

Correct, at the moment the builder images don’t employ srcset. We do plan on revisiting this in a future update, but I can’t give an ETA on when it may be available.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.