I'm trying to add a attribute to the img element from my website in the product gallery. I want it to match the data-value of a swatch selection.
This is the website I'm working on: https://www.blawsomes.com/producto/trachelium-2/
I want the img element to have a data-value or at least the title, right now it only have the img src. I've tried with some functions in PHP, but with no success.
Can somebody help me?
If you use get_the_post_thumbnail() https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/ the third variable you pass, is an array of attributes. So, if you can modify the call in the template
the_post_thumbnail();
to
echo get_the_post_thumbnail($post_id,'thumbnail',array('data-value' => 'the value you want here'));
or, more simply
the_post_thumbnail('thumbnail',array('data-value' => 'the value you want here'));
That should get you close. Note that the $post_id has to be the post of the image you want. So, if it's part of a loop, don't use the global post_id.