Facebook + WordPress = Doing my nut

Facebook integration for a blog tends no longer to be an option – it is a necessity now. One of the aspects of this is getting the correct thumbnail image to display when sharing a post to Facebook.  Getting it working properly has frustrated me no end.  I am in good company, as can be seen by doing a Google search such as “facebook wordpress image_src“.  There is a relatively simple solution, however.

WordPress already has the ability to include a thumbnail for social media sites, known as a Featured Image.  Depending on the theme you are using, you may need to enable this functionality.  This can be done by editing the functions.php in your theme.  To enable Featured Images, add the following lines:

// Add support for Featured Images
if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
    add_image_size('index-categories', 150, 150, true);
    add_image_size('page-single', 350, 350, true);
}

This will now provide you with a “Featured Image” box in the sidebar when editing a post or a page – something like this:

There is just one more step to make sure that WordPress adds the correct tags to the header of your posts to tell Facebook where to find your featured image.  There are a few plugins that can do this for you.  I chose the “FetenWeb image_src Metatag” plugin.

Once that is done, when you, or somebody else, shares one of your pages or posts on Facebook, your featured image will be used as the thumbnail for the post in their feed.  One more useful tool while you are setting things up is the Facebook URL linter, which will help you check that Facebook is correctly selecting the featured image from your posts.