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.
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 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_headcallback, 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/imageorrank_math/opengraph/facebook/add_images. In Rank Math, a URL returned from theimagefilter 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