Disable Pinterest Pin It Button

When using the official Pinterest Hover Pin It plugin, a Pinterest button appears on every image on your site. But you typically don’t want these on archive pages, related posts at the bottom, and anywhere else that isn’t the main content area of the post. A simple fix is to add data-no-pin="no-pin" to all images generated by get_the_post_thumbnail() or wp_get_attachment_image(). Images in the main post content are raw HTML in the post content field – they aren’t generated by these WordPress functions – so are unaffected by this change.

<?php
/**
* Disable PinIt Button
*
*/
function ea_disable_pin_on_images( $attr, $attachment ) {
$attr['data-pin-nopin'] = 'nopin';
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'ea_disable_pin_on_images', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk