How do I hide the featured image from being pinned on Pinterest?

I was told to do this code in my the theme’s functions.php file. I tried it and it would not work.
What should I do? Is there an easier way?

/**

  • Disable pinning of all featured images.
    */
    add_filter( ‘post_thumbnail_html’, function( $html ){
    // Something already has ‘data-pin-nopin’, so we don’t need to modify.
    if ( false !== stripos( $html, ‘data-pin-nopin’ ) ) {
    return $html;
    }
    // Add ‘data-pin-nopin’ to the HTML tag.
    $html = str_replace( '<img ', '<img data-pin-nopin=“true” ', $html );
    return $html;
    });

Would there also be a way to hide other images that are under a certain size from Pinterest? I have a shortcode in for my email opt-in form and it won’t allow me to hide the image from my opt-in form either.
Thanks!

Hi Kimberly,

Thank you for writing in, the code you showed above works fine on my end, it added the attribute data-pin-nopin="true" which disable the pinning of image.

https://developers.pinterest.com/docs/widgets/save/?

Can you confirm that you pasted that code on the child theme’s functions.php file? and you have the child theme activated? If not, please setup a child theme and paste that code on functions.php file.

Regretfully, we can not provide any support for 3rd party plugins.

If you just want to hide the image, maybe we can apply a custom CSS to that, please provide us the page URL where we can see the image.

Cheers!

Hi Friech,
I have the child theme activated and uploaded the updated functions.php file to bluehost. When I click on the pinterest chrome extension the featured image is still showing. Here is the link to the blog post and you can use it for referencing the email opt-in I am talking about for the custom CSS.

I also attached screenshot of the child theme functions.php file so you can see what I did.

Thank you!

Hi Friech,
It turns out I didn’t update Pro. I updated it and now the featured image is not showing as pinnable. Yay! So that solves that problem.
If you could still help with the CSS solution from the link I sent it would be appreciated.

Thank you!

Hey There,

It’s good to know that the issue has been resolved already.

With regards to the custom css for the image within your optin form, you can make use of this custom code:

#mlb2-994726.ml-form-embedContainer .ml-form-embedWrapper .ml-form-embedHeader .sw-pinit a {
    display: none;
}

#mlb2-994726.ml-form-embedContainer .ml-form-embedWrapper .ml-form-embedHeader img {
    pointer-events: none;
}

Best Regards.

Thank you for your help but It is still showing up when I use the Pinterest Chrome extension. I attached a screenshot (image is on the far right that needs to be hidden). I put the code in the style.css file for the child theme. This is the code that Pinterest suggests to use if trying to hide an image if that helps: data-pin-nopin = “nopin”

Hello There,

We are out of option. Regretfully we are not familiar how this plugin works. It is best that you direct your inquiry to the creators of the plugin. They should be able to answer you with a precise and fastest way to resolved your Pinterest issue.

Thank you for your understanding.

Thank you for all your help! I appreciate it!

You’re welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.