G_AUTO automatically added - TURN OFF
Hello,
I've been using wordpress cloudinary plugin for some time and It's working fine, untill I figured out that some images, that have faces, are having 'g_auto' tag in the url even if it's not been enabled or never defined?
For example you can see it here on this page: https://www.degreechoices.com/teaching/
As for example here, it is normal: https://www.degreechoices.com/blog/teachers-in-demand/
Can you please advice how to remove that 'g_auto' from the image url ?
Thank you in advance.
-
Hi Nemanja,
Thanks for reaching out.
This is automatic when adding width and height to your image element. You can modify it by adding this piece of code to your functions.php
/**
* Granular control on Cloudinary crops.
*
* @param array|string $size The size array or slug.
* @param int $attachment_id The attachment ID.
*
* @return array|string
*/
add_filter(
'cloudinary_prepare_size',
function ( $size, $attachment_id ) {
if (
is_array( $size ) &&
(
// Check more about WordPress conditionals here https://developer.wordpress.org/themes/basics/conditional-tags/.
is_post_type_archive( 'product' ) ||
// Check more specific WooCommerce conditionals here https://docs.woocommerce.com/document/conditional-tags/.
is_woocommerce() ||
// Check specific requested image sizes.
'woocommerce_thumbnail' === $size['wpsize']
)
) {
$size['crop'] = 'scale';
unset( $size['gravity'] );
}
return $size;
},
10,
2
);This code is for WooCommerce, so you might need to add a condition depending on how your images are added
Hope that helps.
Best,
Loic
0
Post is closed for comments.
Comments
1 comment