There are a few ways to override Pinterest’s image picker and share a specific image.
- Enable AddToAny image sharing for the quickest way to share a specific image. While it provides share buttons that appear on hover over images, it doesn’t override Pinterest’s picker for your other Pinterest buttons.
- Edit your theme’s template files to add the
data-pin-nopin
attribute to the images you don’t want to appear in Pinterest’s picker.
- Edit your theme’s template files to hardcode AddToAny share buttons and programmatically specify the shared image using the
linkmedia
parameter. Theme developers tend to prefer this method.
- Use AddToAny events to specify the image shared to Pinterest. This can apply to all your AddToAny Pinterest buttons and is probably the best way.
For your site, add the following code to your “Additional JavaScript” box in Settings > AddToAny:
a2a_config.callbacks.push({
share: function(data) {
// Get the main product's image if present on the page
var image = document.querySelector('.woocommerce-product-gallery img.wp-post-image');
// If sharing to Pinterest and a product image is present
if ('Pinterest' === data.service && image && image.src) {
// Set the shared image to the product image
return {
media: image.src
};
}
}
});