0

I know there are many questions and articles about displaying post thumbnail (i.e. featured image) as a thumbnail for Facebook sharing but I'm still having trouble with it.

I'm using AddThis plugin for Wordpress and have a toolbox that shows FB share, Twitter share, G+, Digg, StumbleUpon. When I want to share through Facebook, the title and excerpt show correctly but the thumbnail image is not my featured image but the first image from the body of the post. I can choose an image to use as thumbnail inside a share window and that way use featured image as a thumbnail but I want the featured image to be the first one displayed without the option to change it to any other image from the post.

I tried everything I could think of - plugins that add Open Graph Tags, I tried adding OG Tags manually to head, copy/pasted the tags from four or five different articles, used clear OG Tags and used them inside if statements; I don't know what else to try.

Could you please tell me the exact code that I should put inside my head tags so that when I share through Facebook, there is no option for choosing a thumbnail but that it always shows a thumbnail of a post.

Also, I know FB caches the images when a share request is sent, so I used a new post each time I tested the code.

2 Answers 2

4

Put this in your head

<?php $fb_image = wp_get_attachment_image_src(get_post_thumbnail_id( get_the_ID() ), 'thumnail'); ?>
<?php if ($fb_image) : ?>
    <meta property="og:image" content="<?php echo $fb_image[0]; ?>" />
<?php endif; ?>

To test it out, you don't have to create a new post, just paste your URL in here: https://developers.facebook.com/tools/debug Here you can the data and possibly some errors.

8
  • Yeah, this debugger is great and it does show my featured image as a thumbnail but still if I try and share through my site, the first thumbnail displayed is the first image from the post. I guess I can't stop other images from the post being available for choosing, can I?
    – rlab
    Commented Dec 20, 2011 at 9:38
  • Strainge. Do you have a link to your site so we can check for you? Commented Dec 20, 2011 at 13:51
  • Here, I can create a new post if you want, with the same thumbnail and pics inside a post and you'll see that the first image displayed inside post is always the default thumbnail and you can click the arrow until you get to the featured image.
    – rlab
    Commented Dec 20, 2011 at 14:04
  • 1
    If I lke the page it will show the correct (first) thumbnail. When I share the page it will not use the first thumbnail... Have you tested it with only one thumbnail in your head? Now I see 7 time og:image in your source. Commented Dec 20, 2011 at 14:30
  • 1
    You can disable some plugins and see what happends. Commented Dec 20, 2011 at 15:07
0

I had the same problem, If using wordpress, this plugin worked great!

  • Facebook Featured Image and Open Graph Meta Tags) Version 1.0.1 | By Ryan S. Cowles

I also use the plug

  • Video Thumbnails) Version 2.12 | By Sutherland Boswell,

and in the settings for (video for thumbnails) I have it set to use the featured image as thumbnail, which works great for my site and the open graph facebook plugin to choose the (original non thumbail) for th featured pic for facebook thumb display pic because it then can only have 1 to choose from instead of 2 or more pics and thumbails for your site :)

With using BOTH of these, you can have the best of best worlds!

Not the answer you're looking for? Browse other questions tagged or ask your own question.