/ 2 min read
How to Use Specific Image and Description when Sharing Jekyll Post to Facebook
Often times, when we share our blog post to Facebook, disappointments will arise. Our hard work reduced to zero just because Facebook picks undesireable image and description. Our perfectly written and beautifully arranged blog post looks really bad in the Facebook post… The horror!
However, there is a quick remedy for that, and if you’re using Jekyll, you just need to modify once, and forget about it for the rest of your life. Here’s how!
First, check the front matter format of your blog post’s markdown. Here’s mine for example:
So, in my case, I want the image and the description that are displayed in my Facebook post to be the value of header-img
and subtitle
variables respectively. You can use any variable though, as this is just an example.
Now, open your _include/head.html
template, and this piece of code inside the <head>
tag.
And voila! The next time you share your blog post to Facebook, the post’s header-img
and subtitle
will be used!
To update the already shared posts so that they follow the above schema, you should head to https://developers.facebook.com/tools/debug/, enter your URL, click “Debug”, and click “Scrape Again”.
Now, try to re-share the post. It should be updated now.
We have to do this because Facebook caches the scraped URL. It is especially true if the URL is somewhat recently shared.
Credit due to front-end ninja http://timotiusnc.github.io!