← All guides

CMS Guide

WordPress OG Images: Five Problems and How to Fix Them

How WordPress, Yoast SEO and Rank Math choose an og:image, five reasons a post shares with no image or the wrong one, and the settings and filters that fix each, read from the plugins' own code.

How WordPress produces OG tags

WordPress core does not print Open Graph tags. In WordPress 7.1.5, the callbacks on wp_head print the title, canonical and shortlink, robots, feed links and the generator tag among others, and nothing in wp-includes or the bundled default themes emits an og:image. A site with no SEO plugin and a theme that adds none shares with whatever the platform guesses from the page.

The tags come from a plugin, or from the theme. Yoast SEO and Rank Math both print them, and both pick the image by walking a list and stopping at the first image they can use. The lists are short, and most problems below are the list doing what it says.

Yoast SEO (read in 28.9)

For a post, Yoast tries these in order and stops at the first that produces an image:

  1. Images added by code through the wpseo_add_opengraph_images filter. They go first, so they print first.
  2. The image Yoast has stored for the post. That is the image you chose in the post's Social tab; if there is none, the featured image; then the first gallery image; then the first image in the post content.
  3. Images added through wpseo_add_opengraph_additional_images.
  4. The social image set for the post's content type in Yoast's settings.
  5. The site-wide image, Yoast SEO, Settings, Site basics, Site image, which the settings describe as the fallback for posts and pages that have no images set.

Two details decide a lot of cases. Yoast works the stored image out when the post is saved, not on every request. And it only accepts JPEG, GIF, PNG and WebP attachments, trying the full, large and medium_large sizes in that order and taking the first whose file is 2 MiB (2,097,152 bytes) or smaller. Yoast leaves twitter:image out when it has an Open Graph image and you did not choose a separate X image, so X reads the og:image.

Rank Math (read in 1.0.282)

For a post, Rank Math tries these in order:

  1. Images added through the rank_math/opengraph/facebook/add_images action (twitter in place of facebook for X).
  2. The image chosen in the post's Social tab, then the featured image.
  3. The first usable image in the post content.
  4. Images added through add_additional_images.
  5. The default: Rank Math SEO, Titles & Meta, Global Meta, OpenGraph Thumbnail, described in the plugin as the fallback when no featured image or OpenGraph image is set on the post.

Rank Math tries full, large and medium_large too, but it keeps a size only if both its width and height are between 200 and 2000 pixels, and it accepts JPEG, GIF, PNG, WebP and AVIF. Neither plugin outputs an image for a password-protected post.

The theme

A theme can print its own tags from a wp_head callback, or change the plugin's image through the same filters. A theme that does either is the third source of images on the page, and the least visible one.

Every problem below is a consequence of one of these paths. Each section names the finding in the checker or the site audit that reports it.

Problem 1: the post shares with no image

Symptom

The link unfurls as a title and a line of text. On X it may show a small text card.

Cause

One of these:

  • No plugin prints the tags. Core prints none, so a site with no SEO plugin, and a theme that adds nothing, ships no og:image.
  • The plugin's Open Graph output is off. Yoast has a Social sharing toggle in Site features; with it disabled, its settings say the social image, title and description are not available, and no Open Graph tags print.
  • The post has nothing to pick. No Social tab image, no featured image, no image in the content, and no site-wide default set, so the list runs out.
  • The only image is a type the plugin refuses. An SVG featured image never qualifies: Yoast accepts JPEG, GIF, PNG and WebP, and Rank Math checks the file extension against its list and drops a .svg.
  • The post is password-protected. Both plugins return no images for it.

Fix

Set the site-wide image first (Step 1 below), so no post can ship without one. Then give posts a featured image, or a Social tab image, in a format the plugin accepts.

Detected by

The checker's image_presence check, which reads "Missing og:image", and the audit's image_missing finding. On a site the audit recognises as WordPress, the finding's fix text says to set the plugin's default social image and give the listed posts a featured image.

Problem 2: the post shares with the wrong image

Symptom

The card shows a logo, an author photo, an ad banner from the middle of the article, or a crop that cuts off the headline.

Cause

The lists above pick by position, not by meaning. The usual ways they pick wrongly:

  • No featured image, so a content image wins. Both plugins fall back to the first usable image in the post body, which is often a screenshot or a sponsor logo.
  • An old Social tab image outranks the featured image. A post that had a social image set once keeps it. In both plugins it comes before the featured image.
  • A size was skipped. Yoast takes the first of full, large and medium_large that weighs 2 MiB or less. Rank Math takes the first whose sides are all between 200 and 2000 pixels. A 3000 pixel wide original in Rank Math therefore loses to the large size, which WordPress generates at 1024 pixels wide by default, so the card is soft even though the upload was sharp. A heavy original in Yoast does the same.
  • The aspect ratio is not a card's. A portrait or square featured image is used as it is, and the platform crops it. Facebook asks for at least 1200 by 630 pixels and a ratio near 1.91:1 to show the whole image in the feed.
  • Code ran first. A theme or plugin hooked to wpseo_add_opengraph_images or rank_math/opengraph/facebook/add_images puts its image ahead of everything the editor chose.

Fix

Give each post a featured image cut at 1200 by 630 pixels, under 2 MiB, or set the Social tab image on the posts where the featured image is a poor card. Search the theme and active plugins for the filter names above (Step 3). If you want a card chosen by code, put it in a filter, not a template edit (Step 2).

Detected by

The audit's image_shared finding when one default image is serving pages from different templates (posts, pages and archives all showing the site-wide image), the checker's dimensions check for a card that is not 1200 by 630, and the audit's image_undersized note for cards narrower than 1200 pixels. A wrong image that is correctly sized is something only you can see, in the preview the checker renders for each platform.

Problem 3: you fixed it and the old card still shows

Symptom

The settings are right, the featured image is right, and Facebook, LinkedIn or a messaging app still shows the old card or none.

Cause

Three caches sit between your settings and the card, and each has to be cleared on its own:

  • Your page cache or CDN. A page cache stores the rendered page, head included, so a new featured image or plugin setting changes nothing until the cached copy is purged or expires. Fetch the page as a crawler (see Verify your fix) and read the response headers your cache adds to see whether you are getting a stored copy.
  • Facebook's image cache. Facebook's documentation says images are cached by URL and are not updated unless the URL changes. Replacing a file in the media library under the same file name keeps the URL, so the old card keeps showing. Upload the new card under a new file name instead.
  • The platform's copy of the page. Updating the image for a URL does not update old shares. Fetch the page again through the Sharing Debugger.

Yoast adds one more: it stores the chosen image on the post and recomputes it when the post is saved. A post changed outside the editor (imported, or edited in the database) keeps its old stored image until it is saved again.

Fix

In this order: purge the page cache and the CDN for the post, save the post once, check the served head with curl, then run the URL through the Sharing Debugger. Fixing in a different order re-caches the old card.

Detected by

A stale cache cannot be seen from the page alone. What you can see is the checker reporting an og:image that differs from the one in the editor, and the audit's image_uncacheable finding when the image URL itself answers with headers that forbid caching, which makes every share fetch it from your server.

Problem 4: two things print the tags

Symptom

View source shows two og:image tags, or two og:title tags, and they disagree. Different platforms show different cards.

Cause

More than one source prints Open Graph tags. The common pairs are two SEO plugins active together (a migration left the old one on), an SEO plugin and a theme that prints its own tags, and an SEO plugin and a social sharing or page builder plugin with its own meta output. Each prints in wp_head, and nothing in WordPress core merges them.

The checker reads the first og:image in the document. Facebook's documentation does not say which of several it uses, so a page with two cannot be relied on to look the same everywhere. A page with two og:title tags has the same problem.

Fix

Decide which source owns the tags and turn the others off. Deactivate a leftover SEO plugin. If a different source should own them and you run Yoast, switch off its Open Graph data in Site features, Social sharing. For a theme, see Problem 5. Reload the page source and count: one og:image, unless you intend several.

Detected by

No finding counts duplicate tags. You see it in the page source, with the curl command under Verify your fix, which prints one line per tag.

Problem 5: the theme overrides the plugin

Symptom

The plugin's settings are right and the post has a good featured image, but every page shows the same card, or the card from the theme's options.

Cause

A theme gets two ways to overrule the plugin, and both run on every request:

  • It prints its own tags from a wp_head callback, next to the plugin's (Problem 4 is the result), and the first one in the markup is the one the checker reads.
  • It rewrites the plugin's image through wpseo_opengraph_image, wpseo_add_opengraph_images, rank_math/opengraph/facebook/image or rank_math/opengraph/facebook/add_images. In Rank Math, a URL returned from the image filter replaces the image and skips Rank Math's own validation of it.

Fix

Search the active theme, and any child theme, for the strings og:image, wpseo_ and rank_math/opengraph. Change the theme's option if it has one. If it does not, remove its callback from a child theme (Step 3). A closure cannot be removed by name, so in that case edit the theme or choose a different one.

Detected by

The audit's image_shared finding, when the theme's image lands on pages from several templates, and image_missing when it removes the plugin's image altogether. The theme's source is the confirmation.

The step-by-step fix

Step 1: set a site-wide image

This guarantees that no post and no archive ships without a card.

  • Yoast: Yoast SEO, Settings, Site basics, Site image. Use a 1200 by 630 PNG or JPEG under 2 MiB. If Open Graph data is disabled in Site features, Social sharing, turn it on, or the social fields are unavailable.
  • Rank Math: Rank Math SEO, Titles & Meta, Global Meta, OpenGraph Thumbnail. The plugin recommends 1200 by 630 pixels.

Then set the image for the content types that need their own. In Yoast that is the Social image in the content type's settings. In Rank Math it is the Social tab on the individual post; the Thumbnail for Facebook field in a content type's settings is read for that type's archive page only.

Step 2: choose a card from code, when settings are not enough

Put these in a child theme's functions.php or a small plugin, never in the parent theme, which an update overwrites. They use only filters and actions that exist in Yoast 28.9 and Rank Math 1.0.282.

A fallback for posts that have no image of their own (Yoast). wpseo_add_opengraph_additional_images runs after the post's own image is looked up and before the content-type and site defaults. The callback receives the image container, a Yoast\WP\SEO\Values\Open_Graph\Images object, and changes it in place:

// functions.php of a child theme, or a small must-use plugin
add_filter( 'wpseo_add_opengraph_additional_images', function ( $images ) {
	if ( is_singular( 'post' ) && ! $images->has_images() ) {
		$images->add_image_by_url( get_stylesheet_directory_uri() . '/images/og-default.png' );
	}
	return $images;
} );

A specific card per post (Yoast). wpseo_opengraph_image receives each image's URL and the presentation, and a non-empty string it returns replaces the URL. Here a custom field named og_card_url holds the card:

add_filter( 'wpseo_opengraph_image', function ( $url ) {
	if ( is_singular( 'post' ) ) {
		$card = get_post_meta( get_queried_object_id(), 'og_card_url', true );
		if ( is_string( $card ) && $card !== '' ) {
			return esc_url_raw( $card );
		}
	}
	return $url;
} );

A fallback (Rank Math). The source calls these with do_action, and the hook has one argument, the image object. The loop covers both the Facebook and the X tags:

foreach ( array( 'facebook', 'twitter' ) as $network ) {
	add_action( "rank_math/opengraph/{$network}/add_additional_images", function ( $image ) {
		if ( is_singular( 'post' ) && ! $image->has_images() ) {
			$image->add_image_by_url( get_stylesheet_directory_uri() . '/images/og-default.png' );
		}
	} );
}

A specific card per post (Rank Math). The image filter receives the URL about to be added, or an empty string when the post has none, so this also supplies a card where nothing was found. Register a second filter on rank_math/opengraph/twitter/image if X should differ. A URL returned here is not checked by Rank Math, so it has to be an absolute address of a real, public image:

add_filter( 'rank_math/opengraph/facebook/image', function ( $url ) {
	if ( is_singular( 'post' ) ) {
		$card = get_post_meta( get_queried_object_id(), 'og_card_url', true );
		if ( is_string( $card ) && $card !== '' ) {
			return esc_url_raw( $card );
		}
	}
	return $url;
} );

If the image is in the media library, add_image_by_url in both plugins looks the attachment up and uses its best size, which also fills in the width and height tags.

Step 3: find and remove what is competing

Search the theme and plugins as in Problem 5. To remove a theme's tag callback from a child theme, name the same function and priority the theme used:

add_action( 'init', function () {
	// Name and priority must match the theme's own add_action( 'wp_head', ... ) call.
	remove_action( 'wp_head', 'mytheme_open_graph_tags', 10 );
}, 20 );

It runs at init, after the theme has added its hook. remove_action does nothing when the name or priority differs, so reload the source and check.

Step 4: purge, resave, re-fetch

Purge the page cache and CDN, update each affected post once, then verify as below. Where Facebook cached the old image, upload the new one under a new file name.

Verify your fix

Read the head as a crawler does. Request the page with a crawler's user agent and print the tags. Both plugins write each tag as a <meta> element with property or name first, so this works for either:

curl -sA 'facebookexternalhit/1.1' https://your-site.com/your-post/ \
  | grep -oE '<meta (property|name)="(og|twitter):[^"]*" content="[^"]*"'

Count the og:image lines and open the URL on the one you expect. Run it on one post, one page and one archive, since each takes a different path through the lists above.

Check one URL. The checker scores the card (reachability, dimensions, file size, tags) and renders how it looks on each platform. Enter your post's URL. You can also check this guide's own card.

Audit the whole site. The site audit reads your sitemap, groups URLs into page templates and samples across them. It reports image_missing, image_shared and the other findings above for the templates, so a theme that overrides one post type is caught.

Refresh Facebook's copy. Run the URL through the Facebook Sharing Debugger. Facebook's documentation says the tool triggers a scrape of your page. It does not refresh old shares, and an image under an unchanged URL stays cached, which is why Step 4 renames the file.

A card worth sharing from WordPress

Once the tags are right, the card is what people see. Facebook asks for images of at least 1200 by 630 pixels, a ratio close to 1.91:1, and no more than 8 MB, with 200 by 200 pixels the smallest it accepts. Both plugins can use a 1200 by 630 PNG straight away, which is also well under Yoast's 2 MiB cut-off when it is flat artwork.

A featured image is a poor card for most posts: it is cropped for the blog layout, and it has no title on it. A card made for sharing carries the post's title and your brand, at the size the platforms want.

The properOG generator builds that card from your site's colours and fonts and gives you a clean 1200 by 630 PNG. Upload it as the post's Social tab image, or as the site-wide image in Step 1, and run the checks above.

Frequently Asked Questions

How do I set the Open Graph image in WordPress?

WordPress core prints no Open Graph tags, so use an SEO plugin. Set a site-wide fallback image (in Yoast SEO, Settings, Site basics, Site image; in Rank Math, Titles & Meta, Global Meta, OpenGraph Thumbnail), then give each post a featured image or a Social tab image. A 1200 by 630 pixel PNG or JPEG under 2 MiB works in both plugins.

Why does Yoast or Rank Math show the wrong og:image?

Both pick the first usable image from an ordered list: an image added by code, then the Social tab image, then the featured image, then the first image in the post content, then the site default. A leftover Social tab image, a missing featured image, or a theme filter that adds an image first is the usual cause. Yoast also skips a size over 2 MiB, and Rank Math skips one wider or taller than 2000 pixels.

Why does Facebook still show my old WordPress image?

Facebook caches images by URL and does not update them unless the URL changes. Upload the new card under a new file name, purge your page cache and CDN, resave the post, then fetch the URL again in the Facebook Sharing Debugger. Replacing the file under the same name keeps the old URL, so the old card keeps showing.

Why are there two og:image tags on my WordPress page?

Two sources are printing tags in wp_head: two SEO plugins, or a plugin and a theme or sharing plugin. Turn one off, or remove the theme's callback from a child theme with remove_action. Facebook's documentation does not say which of several og:image tags it uses, so leave one.

Does WordPress add og:image without a plugin?

No. In WordPress 7.1.5 neither core nor the bundled default themes print an og:image. A theme can add its own, which is worth checking in the page source before you install a plugin that will print a second set.

Audit your site

Sample pages across every template in your sitemap and see which ones ship the wrong card, or none. Free, no account needed.

Related guides