Archived topic
Stop the Featured Image from Being Pinnable
3 replies · Started by hoya on October 16, 2019
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;
});
Hi there,
this article explains adding PHP:
https://docs.generatepress.com/article/adding-php/
You should never edit the Theme files, only a Child Theme file.
Thank you! Yes, I would add it to my child theme.
You're welcome