最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

post thumbnails - How can I add a "data-pin-nopin" the featured image html?

programmeradmin3浏览0评论

I really want to prevent my featured images from being pinned. It seems so simple but I just don't have the knowledge to do it apprently.

I found this but it doesn't work. I have divi theme if that matters.

add_filter( 'post_thumbnail_html', function( $html ){
  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;
});

I really want to prevent my featured images from being pinned. It seems so simple but I just don't have the knowledge to do it apprently.

I found this but it doesn't work. I have divi theme if that matters.

add_filter( 'post_thumbnail_html', function( $html ){
  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;
});
Share Improve this question edited Mar 30, 2019 at 15:39 ErinandPhillip Santangelo asked Mar 30, 2019 at 6:24 ErinandPhillip SantangeloErinandPhillip Santangelo 113 bronze badges 2
  • I don't know Divi but I'd assume this happens via CSS, no? Where do you have the suggestion from to set data-pin-nopin? – norman.lol Commented Mar 30, 2019 at 8:32
  • It's the recommended way to prevent someone from pinning an image to pinterest. It has to be added to the image html. Except I cant seem to access that for the featured images. – ErinandPhillip Santangelo Commented Mar 30, 2019 at 15:28
Add a comment  | 

1 Answer 1

Reset to default 0

Simply edit your themes header.php and place the following snippet between the <head></head> tags to prevent pinning globally.

<meta name="pinterest" content="nopin" />

Alternatively you can use the Pinterest Block plugin from which offers you more fine-grained control, also for single posts.

This plugin allows you to block selected posts and pages from getting pinned on Pinterest.

Pinterest Block Features

  • Blocks pages by inserting the official meta tag from Pinterest. Learn more
  • Block specified page types: blog home page, front page, posts, pages, archives.
  • Block selected posts and pages.
发布评论

评论列表(0)

  1. 暂无评论