jekyll-opengraph-image

A Jekyll generator plugin that automatically builds og:image meta tag URLs from a post or page's image: frontmatter field — no theme-specific code required.

Installation

Add to your site's Gemfile:

gem "jekyll-opengraph-image"

Then add to _config.yml:

plugins:
  - jekyll-opengraph-image

Run bundle install.

Usage

In your <head> template

{% if page.og_image %}
<meta property="og:image" content="{{ page.og_image }}" />
{% endif %}

In your frontmatter

---
title: My Post
image: /images/my-post-hero.jpg
---

The plugin reads image:, combines it with your site.url and site.baseurl, and injects the result as page.og_image.

If image: is already an absolute URL (starts with http:// or https://), it is used as-is — useful for CDN-hosted assets.

Configuration

Fallback default image

Set a site-wide default og:image for posts/pages that have no image: frontmatter:

opengraph_image:
  default: /images/default-og.jpg

If a page has no image: and no default is configured, page.og_image is nil and the {% if page.og_image %} guard in your template suppresses the tag cleanly.

How it works

The generator runs at priority :low after all other generators. For each post and page it:

  1. Reads page.image from frontmatter.
  2. Falls back to site.opengraph_image.default if page.image is absent.
  3. Skips the document if neither is present.
  4. If the resolved value is already an absolute URL, uses it unchanged.
  5. Otherwise constructs: site.url + site.baseurl + /image/path.
  6. Writes the result to page.og_image.

Edge cases handled

Scenario Behaviour
image is a relative path Prepended with site.url + site.baseurl
image starts with https:// Used as-is
baseurl is nil or empty Treated as empty string
image has leading/trailing whitespace Stripped
No image + no default og_image not set; template guard suppresses the tag

Requirements

  • Jekyll >= 4.0
  • Ruby >= 2.7

License

MIT © Jason Chance 2025