
jekyll-opengraph-image
A Jekyll plugin that builds absolute og:image URLs from your post frontmatter, with no theme-specific code.
jekyll-opengraph-image fixes a common Jekyll problem. You want the right og:image URL on your post pages, so a shared link shows the post’s hero image and not an empty box.
The Open Graph protocol controls how a URL unfurls when someone shares it: the image, title, and description in the card on Facebook, Mastodon, Slack, iMessage, and others. For content that gets shared, a correct og:image is one of the highest-ROI fixes you can make.
Without a plugin, you’re hardcoding absolute URLs in every post’s frontmatter, counting on a theme-specific fix that won’t move with you, or writing your own Liquid logic in head.html. This generator handles it for every post and page.
How It Works
The generator reads page.image from the frontmatter, builds the absolute URL from site.url and site.baseurl, and puts it in page.og_image. Your head.html template only has to check for page.og_image and write out the tag.
- Relative image paths → prefixed with
site.url + site.baseurl - Absolute URLs (already starting with
https://) → used as-is - Missing image → falls back to
opengraph_image.defaultconfig value - Missing image + no default →
page.og_imagenot set (no broken tag)
Installation
Add to your Gemfile:
gem "jekyll-opengraph-image"
Add to plugins: in _config.yml:
plugins:
- jekyll-opengraph-image
Template Usage
Add to your _includes/head.html:
That’s it. Every post with an image: in its frontmatter now gets the right og:image.
Configuration
You can set a default image for pages that don’t have a hero image:
opengraph_image:
default: /images/social-preview.jpg
Pairs Well With
jekyll-structured-content handles the full JSON-LD schema markup for BlogPosting, WebPage, and other types. Use the two together and you get complete social and search metadata without depending on your theme.
Source
Available on GitHub and RubyGems.
gem install jekyll-opengraph-image

