Site logo

Archived topic

Stop the Featured Image from Being Pinnable

3 replies · Started by hoya on October 16, 2019

Viewing posts 1–4 of 4

I want to prevent my featured images from being pinnable. Should I add the following to the functions.php file?

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

Thank you! Yes, I would add it to my child theme.

You're welcome

This archived topic is closed to new replies.