Show specific thumbnail while sharing on Google+ / Facebook

The problem while sharing an article on google+ or Facebook is, either they show irrelevant thumbnail or nothing at all. To prevent this, you can force the exact thumbnail to be displayed.
To do so, simply include an additional tag in the .

For Facebook

<meta name="og:image" content="http://www.example.com/image.jpg"/>

Update: thanks to ATJ

<meta property="og:image" content="http://www.example.com/image.jpg"/>

For Google+

<meta property="og:image" content="http://www.example.com/image.jpg"/>

Using Custom Fields ( WordPress )

<?php
            global $wp_query;
            $postid = $wp_query->post->ID;

 ?>
      <meta name="og:image" content="<?php echo get_post_meta($postid, ‘thumbnail’, true); ?>"/>
      <meta property="og:image" content="<?php echo get_post_meta($postid, ‘thumbnail’, true); ?>"/>

PS: where thumbnail is the custom fields’ key

^^ we’re not done yet, this snippet works only with single pages ( post page ), which means you’ll get an empty content=”" on the ( Frond page, archives.php …. ), to avoid this all you need to do is to use the is_single function.

Spicific thumbnail for spicific page types

<?php if (is_single()) { ?>
      <?php
            global $wp_query;
            $postid = $wp_query->post->ID;
      ?>
      <meta name="og:image" content="<?php echo get_post_meta($postid, ‘thumbnail’, true); ?>"/>
      <meta property="og:image" content="<?php echo get_post_meta($postid, ‘thumbnail’, true); ?>"/>
     
<?php } else {?>

      <meta name="og:image" content="http://www.example.com/image.jpg" />
      <meta property="og:image" content="http://www.example.com/image.jpg" />

<?php } ?>

Have Fun ^^