How can I control the Facebook like image? [closed]

I have a blog with some posts, and each post has a embedded Facebook like button. Pressing the button opens a dialog so my visitors can share the post on Facebook with a comment.

When sharing, however, the image selected by Facebook is a generic mail icon and not the post thumbnail.

How can I control the image that is used when sharing?


The image that is used for sharing is taken from a chunk of code in the header of your site that will look something like this:

<link rel="image_src" href="" />

Typically it links to the screenshot of your site in the theme. If you removed the code from the header of the file and on single.php put it inside the loop and called your post thumbnail image into the href element I believe it would work. So it would look something like:

<link rel="image_src" href="<?php the_post_thumbnail(); ?>" />

This would mean that if you have like buttons on pages that list multiple posts you probably won’t have an image. If you included some conditional code that removed it only on single.php then you would have the normal image on any page with multiple posts and an like button and the post thumbnail when the single.php template is being used. So the header code would be:

<?php if ( is_single() ) { /* do nothing on single pages */ } else { ?>
<link rel="image_src" href="" />
<?php } ?>

Then you’d still use the code to include the post thumbnail in single.php.

Leave a Comment