Make Facebook use WordPress Post Thumbnail

Here’s a quick code snippet you can use in your WordPress theme to force Facebook to use the Featured Image or Post Thumbnail as the image that appears when you share your page on Facebook.

According to the official Facebook Share specification:

The Post Thumbnail’s width AND height must be at least 50 pixels, and cannot exceed 130×110 pixels. The ratio of both height divided by width and width divided by height (w/h, h/w) cannot exceed 3.0. For example, an image of 126×39 pixels will not be displayed, as the ratio of width divided by height is greater than 3.0 (126/39 = 3.23). Images will be resized proportionally.

WordPress Post Thumbnail displayed in Facebook feed

How to make Facebook share use WordPress Post Thumbnail

In the <head> section of your WordPresss theme insert the following code:

In this example, the size of the image shown for an image attachment is 720 x 405, but can be modified to your needs. You can read more about the sb_get_attachment_image_src function.

About Schalk Burger

Schalk Burger is a Cape Town web designer and WordPress developer.

Read more →

One response to “Make Facebook use WordPress Post Thumbnail

Leave a Reply to Schalk Burger Cancel reply