Incorrect gallery thumbnail image size is used
-
Revisiting this issue yet again.
The image size displayed in the thumbnail slider is
thumbnail(150×150), although the dimensions of the IMG tag are set correctly to those ofwoocommerce_gallery_thumbnail.This is likely due to the following line:
$product_video_thumb_url = wp_get_attachment_image_url( $product_video_thumb_id );Because
wp_get_attachment_image_url()defaults to thethumbnailsize.This line should change to:
$product_video_thumb_url = wp_get_attachment_image_url( $product_video_thumb_id, apply_filters( 'woocommerce_gallery_thumbnail_size', 'woocommerce_gallery_thumbnail' ) );Further down, there’s another issue:
$gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' ); $thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', 'thumbnail' );The result of the first line isn’t used in the second, and without any custom filters, it results in
$thumbnail_sizebeing set tothumbnail. In fact, the value of$gallery_thumbnailisn’t used anywhere below the line that sets it.These lines should be replaced with:
$thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', 'woocommerce_gallery_thumbnail' );But this only changes the image URLs, and we also need to change the dimensions in the IMG tag.
So in the function
get_video_thumbanil_html(), there is direct use of
get_option( 'thumbnail_size_w' )andget_option( 'thumbnail_size_h' ). Instead, the function should get either$thumbnail_sizeas an argument or$propsfrom its called, and usewp_get_attachment_image_src()to get the width and height.wp_get_attachment_image_src()can be used instead ofwp_get_attachment_image_url()to get the URL and the dimensions in one call.BTW, the function
get_video_thumbanil_html()contains a typo and should probably be renamednickx_get_video_thumnbnail_html(), which will also prevent potential name clashes.The page I need help with: [log in to see the link]
The topic ‘Incorrect gallery thumbnail image size is used’ is closed to new replies.