OG Images in WordPress
When someone shares a WordPress post on LinkedIn, Facebook, Slack, or WhatsApp, the preview image comes from the og:image meta tag in the page's <head>. WordPress core doesn't output Open Graph tags itself. In practice they come from an SEO plugin, from your theme, or from code you add.
This guide covers the realistic options in order: what SEO plugins already do, how to change their image with documented filters, how to output the tags yourself with the wp_head hook, and finally how to point og:image at a hosted Unfurlkit URL so every post gets a generated, branded card without anyone designing images by hand.
Sources checked (Oct 2026): WordPress developer reference for
wp_head(https://developer.wordpress.org/reference/hooks/wp_head/), the Yoast developer portal page on OpenGraph image filters (https://developer.yoast.com/features/opengraph/api/wpseo-opengraph-images/), and Rank Math's filters and hooks documentation (https://rankmath.com/kb/filters-hooks-api-developer/).
How WordPress gets an og:image today
wp_head() is the function themes call inside <head> (usually in header.php, or automatically in block themes). It fires the wp_head action, and plugins hook into that action to print tags. WordPress core uses the same hook for the title tag, feeds, canonical links and more, but core does not print og: tags.
So, on most sites:
- An SEO plugin is installed (for example Yoast SEO or Rank Math). It prints
og:imagebased on a per-post social image, the featured image, or a site-wide default. - The theme prints its own tags. Some themes do this, which can conflict with a plugin.
- Nothing prints them. Platforms then guess, often picking a logo or the first image they find, or showing no image.
Rank Math documents its fallback order for the social image as: the OpenGraph image you set in the post, then the featured image, then the first image in the post, then the default OpenGraph thumbnail from its global settings. Yoast also uses a per-post social image, then the featured image and site defaults; check its settings for your version.
The common failure mode
Plugins make it easy to choose an image, but someone still has to make one. On a blog with hundreds of posts, many posts end up with no featured image or with a featured image that's the wrong shape for a 1.91:1 card. Generated images solve that, and that's what the rest of this guide is about.
Option 1: Set images by hand in your SEO plugin
If you publish a few posts a month and have a designer, this is the simplest option:
- Make a 1200×630 image for each post (PNG or JPEG).
- In the post editor, open your SEO plugin's social tab and upload it, or set it as the featured image.
- Set a site-wide default image in the plugin's global settings so pages without one still get a card.
It costs nothing and gives you full control. What it costs is time per post.
Option 2: Change the image with plugin filters
Both major SEO plugins expose filters to change the image URL programmatically. That's how you plug in a generated image without replacing the plugin.
Yoast SEO
Yoast documents wpseo_opengraph_image for altering the Open Graph image. Two details from Yoast's own docs and issue tracker are worth knowing:
- The filter replaces an image that already exists. If Yoast has no
og:imagefor the page, the filter does nothing. To add an image when there is none, Yoast documentswpseo_add_opengraph_imagesandwpseo_add_opengraph_additional_images. - Before Yoast SEO 22.9, changing the URL left
og:image:width/og:image:heightdescribing the original image. Version 22.9 addedwpseo_opengraph_image_width,wpseo_opengraph_image_height, andwpseo_opengraph_image_type.
<?php
// In a small custom plugin or your child theme's functions.php.
add_filter( 'wpseo_opengraph_image', function ( $url ) {
if ( ! is_singular( 'post' ) ) {
return $url;
}
return my_generated_og_url( get_the_ID() ); // defined below
} );
// Yoast SEO 22.9+: keep the dimension tags accurate.
add_filter( 'wpseo_opengraph_image_width', fn () => 1200 );
add_filter( 'wpseo_opengraph_image_height', fn () => 630 );
add_filter( 'wpseo_opengraph_image_type', fn () => 'image/png' );
Because the replacement filter only runs when Yoast already has an image, posts with no featured image and no default image won't be changed. Set a site-wide default image in Yoast so every page has something for the filter to replace.
Rank Math
Rank Math documents a network-specific filter, rank_math/opengraph/{$network}/image, where $network is facebook (the og: tags) or twitter. Rank Math recommends putting its filters in a rank-math.php file in your theme folder, so they only run when the plugin is active.
<?php
// wp-content/themes/your-theme/rank-math.php
add_filter( 'rank_math/opengraph/facebook/image', function ( $attachment_url ) {
return is_singular( 'post' ) ? my_generated_og_url( get_the_ID() ) : $attachment_url;
} );
add_filter( 'rank_math/opengraph/twitter/image', function ( $attachment_url ) {
return is_singular( 'post' ) ? my_generated_og_url( get_the_ID() ) : $attachment_url;
} );
Rank Math sets the image width and height tags from the attachment it picked. Check the output after changing the URL, and make sure the dimension tags you end up with describe a 1200×630 image.
Option 3: Output the tags yourself with wp_head
If you don't run an SEO plugin, or you've turned off its Open Graph output, you can print the tags directly. Don't do this and leave a plugin's Open Graph output on, because you'll get duplicate og:image tags and platforms may pick either one.
<?php
/**
* Plugin Name: Simple OG Tags
*/
add_action( 'wp_head', function () {
if ( ! is_singular() ) {
return;
}
$post_id = get_queried_object_id();
$title = get_the_title( $post_id );
$desc = wp_strip_all_tags( get_the_excerpt( $post_id ) );
$url = get_permalink( $post_id );
$image = my_generated_og_url( $post_id );
printf( '<meta property="og:type" content="article" />' . "\n" );
printf( '<meta property="og:title" content="%s" />' . "\n", esc_attr( $title ) );
printf( '<meta property="og:description" content="%s" />' . "\n", esc_attr( $desc ) );
printf( '<meta property="og:url" content="%s" />' . "\n", esc_url( $url ) );
printf( '<meta property="og:image" content="%s" />' . "\n", esc_url( $image ) );
echo '<meta property="og:image:width" content="1200" />' . "\n";
echo '<meta property="og:image:height" content="630" />' . "\n";
echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
printf( '<meta name="twitter:image" content="%s" />' . "\n", esc_url( $image ) );
} );
get_permalink() returns an absolute URL, which matters because og:image and og:url must be absolute. Always escape output (esc_attr, esc_url). Post titles are user content.
The DIY image generator, honestly
Options 2 and 3 still need a my_generated_og_url() that returns an image. If you want to generate images inside WordPress itself, the realistic routes are:
- PHP image libraries (GD or Imagick). Draw a background, write the title with a TTF font, and save into
wp-content/uploads. That works, but text wrapping, font fallback, and emoji are all manual, and you have to regenerate the file whenever a title changes. - A generator plugin. Some plugins do this for you. Quality and maintenance vary, so read the support forums before you commit.
- A separate Node service running Satori or
@vercel/og. This gives you good layout (flexbox, real fonts), but now you run a second service next to WordPress.
Each of these works, but each adds something to maintain: fonts, a cache folder, regeneration on edit, and server CPU on busy sites.
Option 4: One URL with Unfurlkit
Unfurlkit renders the image for you. my_generated_og_url() just builds a URL:
<?php
/**
* Build an Unfurlkit OG image URL for a post.
*/
function my_generated_og_url( $post_id ) {
$params = array(
'title' => wp_strip_all_tags( get_the_title( $post_id ) ) ?: get_bloginfo( 'name' ), // title must be non-empty
'theme' => 'dark', // 'dark' or 'light'
// 'subtitle' => get_bloginfo( 'name' ),
// 'accent' => '7c3aed', // hex without '#'
);
return 'https://unfurlkit.com/v1/basic.png?' . http_build_query( $params, '', '&', PHP_QUERY_RFC3986 );
}
The basic template accepts title, subtitle, theme (dark or light), and accent (6-digit hex, no #). Unknown parameters are rejected with a 400, so keep to these. Titles are trimmed to 120 characters and subtitles to 160.
The URL above has no key yet: every image URL needs your key. A free key gets 10 renders in total (no monthly reset), with a small "unfurlkit" watermark, and needs no card. On Pro ($9/mo or $90/yr, 10,000 renders a month, no watermark, custom fonts (Inter, Roboto, Playfair Display, JetBrains Mono) and logo), you add your public key k and a signature s, computed on the server with your secret key:
<?php
// Pro: sign on the server. Never expose the secret key in front-end code.
// Scheme per SPEC.md §2: HMAC-SHA256 (secret as UTF-8 bytes) over path + "?" + params sorted by UTF-16 code unit, RFC 3986-encoded; base64url, no padding, first 16 chars.
function my_signed_og_url( $post_id ) {
$params = array(
'title' => wp_strip_all_tags( get_the_title( $post_id ) ) ?: get_bloginfo( 'name' ), // title must be non-empty
'theme' => 'dark',
'k' => UNFURLKIT_PUBLIC_KEY, // define in wp-config.php
);
// Sort keys by UTF-16 code unit (UTF-16BE byte order matches it). Keys are unique, so no value tie-break is needed.
uksort( $params, fn ( $a, $b ) => strcmp( mb_convert_encoding( $a, 'UTF-16BE', 'UTF-8' ), mb_convert_encoding( $b, 'UTF-16BE', 'UTF-8' ) ) );
$path = '/v1/basic.png';
$canonical = $path . '?' . http_build_query( $params, '', '&', PHP_QUERY_RFC3986 );
$raw = hash_hmac( 'sha256', $canonical, UNFURLKIT_SECRET_KEY, true );
$sig = substr( rtrim( strtr( base64_encode( $raw ), '+/', '-_' ), '=' ), 0, 16 );
return 'https://unfurlkit.com' . $canonical . '&s=' . $sig;
}
What this changes compared with DIY:
- No image files in
uploadsand no regeneration step. Change the title and the URL changes, so the image does too. - No server CPU spent drawing images.
- Correct by default: 1200×630 PNG at an absolute HTTPS URL.
- Works with or without an SEO plugin. Use the Yoast or Rank Math filter, or the
wp_headhook.
What counts as a render: a render is counted only when a unique image is generated and wasn't already cached. Shares and cache hits don't count. Over the limit, images keep rendering. On a signed Free key, images already made keep showing, and new ones get a plain version (your title on the basic card, with the small mark) that doesn't count. Upgrade to Pro for more renders. Upgrade to Pro to remove watermarks from all your images.
Which option should you use?
| Situation | Use |
|---|---|
| Few posts, designer on hand | Set images by hand in your SEO plugin |
| Already on Yoast or Rank Math | Their image filter plus a generated URL |
| No SEO plugin, want full control | wp_head hook |
| Don't want to run an image generator | Unfurlkit URL |
Debugging checklist
- View source of the live post (not the editor preview). Is there exactly one
og:image? Duplicates usually mean a theme and a plugin are both printing tags. - Is the URL absolute and
https://? - Open the image URL in a private window. It should return 200 with an image content type. With Unfurlkit, a
400means an invalid parameter, so checkthemeandaccent. - Caching plugins and CDNs. If you changed the image but the HTML still shows the old tag, purge your page cache.
- Security plugins and firewalls sometimes block crawler user-agents. LinkedIn's help notes that a site blocking its crawler is one reason an image that meets the requirements still doesn't appear.
- Refresh platform caches. Use Meta's Sharing Debugger (https://developers.facebook.com/tools/debug/) and LinkedIn's Post Inspector (https://www.linkedin.com/post-inspector/). Both are official tools that can re-fetch a URL.
- Run the page through the Free OG Image Checker to see previews for X, LinkedIn, Facebook, WhatsApp, Slack, Discord, and iMessage, plus a list of fixes. We don't store the URLs you check.
FAQ
Which languages and scripts are supported? Right-to-left scripts such as Arabic and Hebrew aren't supported yet at launch.
Do I need an SEO plugin for Open Graph?
No. WordPress core doesn't print og: tags, but a few lines on the wp_head hook do. Most sites use a plugin because it also handles titles, descriptions, sitemaps, and schema.
Will changing the image URL hurt SEO?
og:image affects how links look when shared. Google's ranking isn't documented to depend on it, so treat it as a sharing feature.
Can I use different images for X and Facebook?
Yes. Rank Math has separate facebook and twitter filters, and with the wp_head approach you control og:image and twitter:image independently.
What about WooCommerce products?
The same approach works. Build the URL from the product name. Or use the dedicated product template for a name, tagline and price.
Summary
WordPress leaves Open Graph to plugins and themes. You can pick images by hand, swap them with documented Yoast or Rank Math filters, or print tags yourself on wp_head. The hard part is producing an image for every post, and one Unfurlkit URL handles that.
See Unfurlkit pricing · Check any page with the Free OG Image Checker.