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

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="https://wordpress.stackexchange.com/questions/3605/path/to/theme/screenshot.png" />

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="https://wordpress.stackexchange.com/questions/3605/<?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="https://wordpress.stackexchange.com/questions/3605/path/to/theme/screenshot.png" />
<?php } ?>

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

Leave a Comment