How to add data-pin-nopin=”true” to an image with PHP

How can I add data-pin-nopin=”true” to an image with PHP (or any other language)? Currently, my site logo image is pinnable and I don’t want that, but I don’t know how to do it.

There is a code that makes featured images of all posts not pinnable using the data-pin-nopin attribute.

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 <img> HTML tag.
$html = str_replace( ‘<img ‘, ‘<img data-pin-nopin=”true” ‘, $html );
return $html;
});

Can I do something similar to add data-pin-nopin=”true” to my logo image or any image? Maybe grab the image by its source and add the data-pin-nopin=”true” attribute?

Can you please help?

Read more here:: How to add data-pin-nopin=”true” to an image with PHP

Leave a Reply

Your email address will not be published. Required fields are marked *