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