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.

/**
 * 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 );

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

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

Let's Talk