Show specific thumbnail while sharing on Google+ / Facebook
Posted by Fahdos on Oct 12th, 2011 in Web & Design
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
Update: thanks to ATJ
For Google+
Using Custom Fields ( WordPress )
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
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 ^^








Oct 13th