📝 WordPress: Fix Featured Images Missing on the AMP Version of a Post
Most AMP plugins generate their markup from a post’s content and template independently of the normal theme, which means a featured image set through a theme’s own custom meta box — rather than the native _thumbnail_id post meta key that set_post_thumbnail() writes to — is invisible to the AMP renderer even though it displays perfectly on the regular, non-AMP page.
🔎 The Problem
// Regular theme template - works fine
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'large' );
}
// AMP plugin's own template hook reads the same function,
// but the image was actually set via a theme option field
// (update_post_meta($id, 'theme_custom_hero_image', $url))
// instead of set_post_thumbnail() -> _thumbnail_id was never set
// has_post_thumbnail() returns false under the AMP template too
✅ Fix: Make the Native Thumbnail the Source of Truth
- Set the image through the standard Featured Image panel (which calls
set_post_thumbnail()) instead of a theme’s custom hero-image field, so every consumer of_thumbnail_id— AMP plugin included — sees the same value. - If the custom field must stay for legacy reasons, hook into
save_postto mirror its value intoset_post_thumbnail()as well, so both code paths stay in sync going forward. - Run a one-time script over existing posts that backfills
_thumbnail_idfrom the custom field, so AMP pages for already-published posts pick up the same image without re-editing each one by hand.
🚨 Why This Is Dangerous
- A post that looks complete in the regular editor preview can render with a blank, broken-looking header on every AMP page Google serves from search results, which is exactly the version of the page most mobile visitors actually land on.
A plugin that reads the standard featured-image field will never see an image that was only ever saved somewhere else.





