Yes, the global post object is already set when wp_head
is called. An example for a function body from this post:
// restricted to singular pages only
if ( ! is_singular() )
return;
// there has to be a featured image set
$thumb_id = get_post_thumbnail_id();
if ( empty ( $thumb_id ) )
return;
// FALSE or array
$image = wp_get_attachment_image_src( $thumb_id );
// nothing found for unknown reasons
if ( empty ( $image ) )
return;
// make sure it is a real url
$src = esc_url( $image[ 0 ] );
// esc_url() returns an empty string for some invalid URLs
if ( '' !== $src )
print "<meta property='http://ogp.me/ns#image' content="$src" />";