[Support request] Prevent post featured image from pinning to Pinterest

Home Forums Support [Support request] Prevent post featured image from pinning to Pinterest

Home Forums Support Prevent post featured image from pinning to Pinterest

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2057035
    Tamarah

    Images that should not be allowed to pin to Pinterest get a class assigned -> data-no-pin=”no-pin”
    I can easily do this with a plugin (Grow Social) or when editing an image in HTML but it’s not possible with the featured image very easily. Is there a hook or code I can add that will add the code (data-no-pin=”no-pin”) to the featured image of every post?

    #2057196
    Elvin
    Staff
    Customer Support

    Hi there,

    Will this be for the Single post page and Archive pages?

    If so, you can do it with this PHP snippet:

    add_filter( 'wp_get_attachment_image_attributes', function( $atts ) {
    	$atts['data-no-pin'] = 'no-pin';
    
    	return $atts;
    } );

    If it’s only for the single post pages, try this:

    add_filter( 'wp_get_attachment_image_attributes', function( $atts ) {
    	if( is_single() ){
    		$atts['data-no-pin'] = 'no-pin';
    	}
    	return $atts;
    } );
    #2058073
    Tamarah

    Thank you. I decided to suppress featured images from showing at all so Google can get to the content faster. (I still want the featured image to be used in the post lists via WP Show Posts).

    I’ll keep the code you provided in case something changes.

    #2061325
    Elvin
    Staff
    Customer Support

    No problem. Let us know if you need further help with it. 😀

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.