in WooCommerce or in WordPress in general we have size names like: thumbnail
, woocommerce_thumbnail
, woocommerce_gallery_thumbnail
...
How to get the size width and height just from the size name ?
I mean exactly the contrary of Get image's size name from it's dimension
My Answer:
You can use the `wc_get_image_size` function in WooCommerce to get the width and height of a specific image size by its name. Here's an example of how you can do this:
php
$image_size_name = 'woocommerce_thumbnail'; // The name of the image size you want to get the dimensions for
$image_size = wc_get_image_size( $image_size_name );
if ( $image_size ) {
$width = $image_size['width'];
$height = $image_size['height'];
echo "Width: $width, Height: $height";
} else {
echo "Image size not found";
}
This code will retrieve the width and height of the image size with the name 'woocommerce_thumbnail'. You can replace the `$image_size_name` variable with any other size name you want to get the dimensions for.
Rate this post
3 of 5 based on 1925 votesComments