I’m aware that when people share pages from your site on Facebook it uses the “image_src” tag to find a preview image. I want Facebook to look for a post thumbnail and use that first, and if that’s not present, to use a default.
Can someone just verify that this code should work? I think Facebook isn’t caching/catching up right now, but I just want a nod from someone more advanced to make sure I’m not making a fundamental mistake.
<link rel="image_src" href="
<?php
if ( has_post_thumbnail() ) {
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );
echo $thumbnail_src;
}
else echo "/link.jpg"; ?>
" />
Why don’t you use Facebook’s Open Graph META to define the image (for share) and as long as your thumbnail is set as the Featured image the below code (found here) should work.