To answer this one and point to the real problem:
As the <head>
HTML tag comes far before the actual loop, you’ll need something else than the global $post
.
get_queried_object();
get_queried_object_id();
The plugin
The code is tested and works.
As you might want to keep this functionality when switching themes, I’d suggest wrapping it up in a plugin.
So the actual plugin should be something around the following lines:
<?php
/** Plugin Name: (#70215) »kaiser« Post Thumbnail image for FB */
function wpse70215_fb_img()
{
// Not on a single page or post? Stop here.
if ( ! is_singular() )
return;
$post_ID = get_queried_object_id();
// We got no thumbnail? Stop here.
if ( ! has_post_thumbnail( $post_ID ) )
return;
// Get the Attachment ID
$att_ID = get_post_thumbnail_id( $post_ID );
// Get the Attachment
$att = wp_get_attachment_image_src( $att_ID );
printf(
'<link rel="image_src" href="https://wordpress.stackexchange.com/questions/70215/%s">'
,array_shift( $att )
);
}
add_action( 'wp_head', 'wpse70215_fb_img' );