How to add Open Graph tags in WordPress
WordPress does not add Open Graph tags by itself. Share a bare WordPress page and Facebook or LinkedIn decides what goes in the preview — often the wrong image. There are two routes: an SEO plugin (easy, recommended) or manual code.
The free checker shows your previews for nine platforms — from X and WhatsApp to iMessage, Discord and Bluesky.
Route 1 (recommended): a free SEO plugin
Install Yoast SEO or Rank Math (both free). They automatically generate og: tags for every page, using your featured image as og:image. Per page/post you can set a different title, description and image in the plugin panel under "Social".
Set a site-wide fallback
In the plugin settings, set a default social image (1200×630) for pages without a featured image. That way there is never an empty preview.
Route 2: manually with code
If you prefer no plugin, you can print tags via the wp_head hook in your (child) theme's functions.php. See the code example below. Only sensible if you know what you are doing — a plugin update cannot break, your own code can.
Check the result
Paste a page URL into the MetaPeek checker. If you see duplicate tags or the wrong image, check "Common mistakes" below.
Code example
// functions.php of your child theme — only if you do NOT use an SEO plugin
add_action('wp_head', function () {
if (!is_singular()) return;
$title = esc_attr(get_the_title());
$url = esc_url(get_permalink());
$img = esc_url(get_the_post_thumbnail_url(null, 'large'));
$desc = esc_attr(wp_trim_words(get_the_excerpt(), 25));
echo "<meta property='og:title' content='{$title}' />\n";
echo "<meta property='og:description' content='{$desc}' />\n";
echo "<meta property='og:type' content='article' />\n";
echo "<meta property='og:url' content='{$url}' />\n";
if ($img) echo "<meta property='og:image' content='{$img}' />\n";
echo "<meta name='twitter:card' content='summary_large_image' />\n";
});Common mistakes
- Duplicate tags from plugin + own codeTwo sets of og: tags on one page gives unpredictable previews. Pick one route: either the plugin, or manual code — never both.
- Caching plugin serving old HTMLPlugins like WP Rocket or W3 Total Cache can serve old pages with old tags. Clear the cache after every change.
- Theme already printing its own tagsSome themes ship built-in "social meta". Check with MetaPeek whether tags already exist before adding a plugin.
Frequently asked questions
Which plugin is best for Open Graph?
For og: tags alone it hardly matters: Yoast SEO and Rank Math both handle it fine in their free versions. Pick whichever you already use for SEO.
Why does Facebook still show the old image?
Facebook caches previews per URL. Your new tags are probably in place (verify with MetaPeek); the cache refreshes on its own, or force it via Facebook's Sharing Debugger with "Scrape Again".
Do I have to pay for social previews?
No. The free versions of the major SEO plugins handle Open Graph completely.
Paste your URL and see within two seconds whether everything is right — on every platform.