Use featured image description in Pinterest

When someone clicks your Pinterest sharing button, Shared Counts uses the current post’s featured image as the image, and the current post’s title as the description.

Want a more descriptive description? The code below will use the featured image’s description if provided, and if empty it will fall back to the post title.

This code snippet goes in a core functionality plugin or Code Snippets.

 * Pinterest button, use image description 
 * @link
 * @param array $link
 * @param int $post_id
 * @param string $style 
 * @return array $link 
function be_pinterest_image_description( $link, $post_id, $style ) {
	if( 'pinterest' === $link['type'] && has_post_thumbnail( $post_id ) ) {
		$description = get_post( get_post_thumbnail_id( $post_id ) )->post_content;
		if( empty( $description ) )
			$description = $link['title'];
		$link['link'] = '' . $link['url'] . '&media=' . $link['img'] . '&description=' . rawurlencode( wp_strip_all_tags( $description ) );
	return $link;
add_filter( 'shared_counts_link', 'be_pinterest_image_description', 10, 3 );

Filters used:

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.