Title: Pinterest Button Problem
Last modified: August 12, 2021

---

# Pinterest Button Problem

 *  Resolved [marinelam](https://wordpress.org/support/users/marinelam/)
 * (@marinelam)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/pinterest-button-problem-2/)
 * Could you help me with the Pinterest Button, when I click, it populates random
   images from my posts and not the Pin Image I want to show? How can I fix this?
   
   Thanks
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fpinterest-button-problem-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [micropat](https://wordpress.org/support/users/micropat/)
 * (@micropat)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/pinterest-button-problem-2/#post-14763284)
 * Hi Marinela,
 * Instead of opening Pinterest’s image picker, you can have AddToAny share the 
   page’s main “preview” image to Pinterest by adding a block of code to the plugin.
 * Add the following code to your “Additional JavaScript” box in Settings > AddToAny:
 *     ```
       // Share the page's "og:image" to Pinterest instead of loading Pinterest's image picker.
       a2a_config.callbacks.push({
           share: function(data) {
               if ( 'Pinterest' === data.service ) {
                   var image = document.querySelector('meta[property="og:image"]');
                   if (image) data.media = image.getAttribute('content');
               }
               return data;
           }
       });
       ```
   
 * This code uses [AddToAny event handling](https://www.addtoany.com/buttons/customize/wordpress/events)
   to share a specific image to Pinterest. WordPress developers can alternatively
   specify the `media` using the [AddToAny shortcode](https://wordpress.org/plugins/add-to-any/#what%20is%20the%20shortcode%20for%20sharing%3F)
   or using [PHP code](https://wordpress.org/plugins/add-to-any/#how%20can%20i%20place%20the%20share%20buttons%20in%20a%20specific%20area%20of%20my%20site%3F).
 *  Thread Starter [marinelam](https://wordpress.org/support/users/marinelam/)
 * (@marinelam)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/pinterest-button-problem-2/#post-14764025)
 * Thank you for your prompt reply.
 * I added the code but that doesn’t resolve my problem. Now when I click on the
   Pinterest share button it leads me to share the first photo of my post. My question
   is how to make shareable only the image from my post that I want to be pinnable(
   not the first photo of every post).
    For example, in the link I sent you, that
   is the last image with the text on it (at the end of my post). I want only that
   photo to show in the options when someone clicks on the Pinterest button and 
   that one should be shared :)) I hope you understand.
 *  Plugin Author [micropat](https://wordpress.org/support/users/micropat/)
 * (@micropat)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/pinterest-button-problem-2/#post-14774713)
 * Ah, I see what you’re going for with Pinterest. 🙂
 * Since the code above uses the preview image “meta tag” set by the Yoast plugin
   on your site, if you want your image-with-text-on-it to be used by both Pinterest
   _and_ Facebook, I’d suggest just changing the image with Yoast and keeping the
   above code.
 * To use your preferred image-with-text-on-it for Pinterest only, you’ll need to
   give the image a unique `class` name. If you’re using the WordPress Editor, tap
   the image, go the Block tab > Advanced > Additional CSS class(es) and give it
   a `class` name such as `the-pinterest-image`.
 * Then add the following code to your “Additional JavaScript” box in Settings >
   AddToAny:
 *     ```
       // Share the page's ".the-pinterest-image" to Pinterest instead of loading Pinterest's image picker.
       a2a_config.callbacks.push({
           share: function(data) {
               if ( 'Pinterest' === data.service ) {
                   var image = document.querySelector('.the-pinterest-image');
                   if (image) data.media = image.getAttribute('src');
               }
               return data;
           }
       });
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Pinterest Button Problem’ is closed to new replies.

 * ![](https://ps.w.org/add-to-any/assets/icon.svg?rev=972738)
 * [AddToAny Share Buttons](https://wordpress.org/plugins/add-to-any/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/add-to-any/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/add-to-any/)
 * [Active Topics](https://wordpress.org/support/plugin/add-to-any/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/add-to-any/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/add-to-any/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [micropat](https://wordpress.org/support/users/micropat/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/pinterest-button-problem-2/#post-14774713)
 * Status: resolved