Social Metadata Hardening Skill
Fix social sharing so every important URL unfurls as a rich card across all platforms.
When to Use
- Use when shared links show missing, stale, cropped, or incorrect previews on social and chat platforms.
- Use when auditing Open Graph, Twitter/X card, image URL, alt text, or
metadataBase coverage in a web app.
- Use before launch when every public page needs predictable rich previews across LinkedIn, X, Facebook, WhatsApp, Slack, Discord, and Telegram.
Why Previews Break
| Problem |
Root Cause |
| No preview at all |
Missing og:title, og:description, or og:image |
| Broken image |
Relative URL (must be absolute) |
| Wrong image size |
Image not 1200×630px (OG standard) |
| Plain text card |
Twitter card type missing or set to summary |
| Stale preview |
Platform caching old metadata |
| Metadata missing on crawl |
Tags added by client-side JS (crawlers don't run JS) |
The Gold Standard Metadata Block
Every shareable page needs ALL of these in static HTML:
// Next.js App Router — lib/socialMetadata.js
export function buildSocialMetadata({
title,
description,
path, // '/blog/my-post'
image, // '/images/og/my-post.jpg' or full URL
imageAlt,
imageWidth = 1200,
imageHeight = 630,
}) {
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://www.yourdomain.com';
// Always produce an absolute URL
const imageUrl = image?.startsWith('http') ? image : `${baseUrl}${image}`;
const pageUrl = `${baseUrl}${path}`;
// Detect MIME type from extension
const ext = imageUrl.split('.').pop().toLowerCase();
const mimeMap = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp' };
const imageType = mimeMap[ext] || 'image/jpeg';
return {
title,
description,
alternates: { canonical: pageUrl },
openGraph: {
title,
description,
url: pageUrl,
type: 'website', // use 'article' for blog posts
images: [{
url: imageUrl,
secureUrl: imageUrl, // explicit HTTPS version
width: imageWidth,
height: imageHeight,
alt: imageAlt || title,
type: imageType,
}],
},
twitter: {
card: 'summary_large_image', // NOT 'summary' — that shows a tiny image
title,
description,
images: [imageUrl],
},
};
}
Applying the Helper
Static page
// app/about/page.js
import { buildSocialMetadata } from '@/lib/socialMetadata';
export const metadata = buildSocialMetadata({
title: 'About Us | My Site',
description: 'Learn about our team and mission.',
path: '/about',
image: '/images/og/about.jpg',
imageAlt: 'The My Site team',
});
Dynamic page (blog post, tool page)
// app/blog/[slug]/page.js
import { buildSocialMetadata } from '@/lib/socialMetadata';
export async function generateMetadata({ params }) {
const post = await getPost(params.slug);
return buildSocialMetadata({
title: `${post.title} | My Blog`,
description: post.excerpt,
path: `/blog/${params.slug}`,
image: post.ogImage || '/images/og/default.jpg',
imageAlt: post.title,
});
}
Homepage (app/layout.js or app/page.js)
export const metadata = {
metadataBase: new URL('https://www.yourdomain.com'), // REQUIRED for absolute URLs
...buildSocialMetadata({
title: 'My Site — Tagline Here',
description: 'Site-wide description.',
path: '/',
image: '/images/og/home.jpg',
}),
};
⚠️ Set metadataBase when using relative metadata URLs. If your helper already outputs absolute canonical/OG URLs, previews can still work without it.
OG Image Checklist
Good OG images:
- 1200 × 630px (2:1 ratio — works on all platforms)
- Under 8MB (Facebook limit)
- Served over HTTPS
- File name has no spaces (use hyphens)
- Format: JPEG or PNG (WebP works on most but not all crawlers)
- Accessible via GET with no authentication
# Verify your OG image is reachable and correct size
curl -sI https://www.yourdomain.com/images/og/home.jpg | grep -i "content-type\|content-length\|status"
Platform-Specific Notes
Facebook / Meta
- Caches aggressively — use the Sharing Debugger to force recrawl
- Minimum image: 200×200px (but use 1200×630 for quality)
- Needs:
og:title, og:description, og:image, og:url
X / Twitter
- Use
twitter:card = summary_large_image for full-width images
twitter:image must be an absolute URL
- Use the Card Validator to test
LinkedIn
- Caches hard — use Post Inspector to refresh
- Respects
og: tags; ignores twitter: tags
- Image must be ≥1.91:1 aspect ratio
WhatsApp / Telegram
- Read OG tags on first share; cache can last hours
- Re-share after a few hours for the cache to clear naturally
Slack / Discord
- Both use OG tags; both cache
- Discord also supports
og:type = article for richer embeds
Debugging Social Previews
1. Check raw HTML for tags
curl -s https://www.yourdomain.com/blog/my-post | grep -i "og:\|twitter:"
If tags don't appear → they're being added by JavaScript (not crawlable). Fix: move to export const metadata or generateMetadata.
2. Validate with platform tools
3. Force cache refresh
After deploying fixes, paste the URL into each platform's debugger and click "Fetch new scrape information" (or equivalent).
Social Metadata Checklist
Limitations
- Cannot force immediate cache refresh on every social platform; some previews may remain stale after a correct fix.
- Requires publicly reachable deployed URLs for reliable validation with platform debuggers.
- Does not replace brand, accessibility, or legal review of image text, alt text, and preview copy.
1---2name: social-metadata-hardening3description: "Fix social sharing previews so URLs render as rich cards on Facebook, LinkedIn, X/Twitter, WhatsApp, Telegram, and more. Covers OG tags, Twitter cards, absolute image URLs, and debugging."4category: seo5risk: safe6source: self7source_type: self8date_added: "2026-05-31"9author: Whoisabhishekadhikari10tags: [seo, open-graph, twitter-card, social-sharing, og-image, nextjs, metadata]11tools: [claude, cursor, gemini, claude-code]12version: 1.0.013metadata:14 source: https://skillmd.com/skills/mhassan0000/social-metadata-hardening15---1617# Social Metadata Hardening Skill1819Fix social sharing so every important URL unfurls as a rich card across all platforms.2021---2223## When to Use2425- Use when shared links show missing, stale, cropped, or incorrect previews on social and chat platforms.26- Use when auditing Open Graph, Twitter/X card, image URL, alt text, or `metadataBase` coverage in a web app.27- Use before launch when every public page needs predictable rich previews across LinkedIn, X, Facebook, WhatsApp, Slack, Discord, and Telegram.2829---3031## Why Previews Break3233| Problem | Root Cause |34|---------|-----------|35| No preview at all | Missing og:title, og:description, or og:image |36| Broken image | Relative URL (must be absolute) |37| Wrong image size | Image not 1200×630px (OG standard) |38| Plain text card | Twitter card type missing or set to `summary` |39| Stale preview | Platform caching old metadata |40| Metadata missing on crawl | Tags added by client-side JS (crawlers don't run JS) |4142---4344## The Gold Standard Metadata Block4546Every shareable page needs ALL of these in static HTML:4748```js49// Next.js App Router — lib/socialMetadata.js50export function buildSocialMetadata({51 title,52 description,53 path, // '/blog/my-post'54 image, // '/images/og/my-post.jpg' or full URL55 imageAlt,56 imageWidth = 1200,57 imageHeight = 630,58}) {59 const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://www.yourdomain.com';60 61 // Always produce an absolute URL62 const imageUrl = image?.startsWith('http') ? image : `${baseUrl}${image}`;63 const pageUrl = `${baseUrl}${path}`;64 65 // Detect MIME type from extension66 const ext = imageUrl.split('.').pop().toLowerCase();67 const mimeMap = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp' };68 const imageType = mimeMap[ext] || 'image/jpeg';6970 return {71 title,72 description,73 alternates: { canonical: pageUrl },74 openGraph: {75 title,76 description,77 url: pageUrl,78 type: 'website', // use 'article' for blog posts79 images: [{80 url: imageUrl,81 secureUrl: imageUrl, // explicit HTTPS version82 width: imageWidth,83 height: imageHeight,84 alt: imageAlt || title,85 type: imageType,86 }],87 },88 twitter: {89 card: 'summary_large_image', // NOT 'summary' — that shows a tiny image90 title,91 description,92 images: [imageUrl],93 },94 };95}96```9798---99100## Applying the Helper101102### Static page103```js104// app/about/page.js105import { buildSocialMetadata } from '@/lib/socialMetadata';106107export const metadata = buildSocialMetadata({108 title: 'About Us | My Site',109 description: 'Learn about our team and mission.',110 path: '/about',111 image: '/images/og/about.jpg',112 imageAlt: 'The My Site team',113});114```115116### Dynamic page (blog post, tool page)117```js118// app/blog/[slug]/page.js119import { buildSocialMetadata } from '@/lib/socialMetadata';120121export async function generateMetadata({ params }) {122 const post = await getPost(params.slug);123 return buildSocialMetadata({124 title: `${post.title} | My Blog`,125 description: post.excerpt,126 path: `/blog/${params.slug}`,127 image: post.ogImage || '/images/og/default.jpg',128 imageAlt: post.title,129 });130}131```132133### Homepage (app/layout.js or app/page.js)134```js135export const metadata = {136 metadataBase: new URL('https://www.yourdomain.com'), // REQUIRED for absolute URLs137 ...buildSocialMetadata({138 title: 'My Site — Tagline Here',139 description: 'Site-wide description.',140 path: '/',141 image: '/images/og/home.jpg',142 }),143};144```145146> ⚠️ **Set `metadataBase` when using relative metadata URLs.** If your helper already outputs absolute canonical/OG URLs, previews can still work without it.147148---149150## OG Image Checklist151152Good OG images:153- **1200 × 630px** (2:1 ratio — works on all platforms)154- **Under 8MB** (Facebook limit)155- Served over **HTTPS**156- File name has **no spaces** (use hyphens)157- Format: **JPEG or PNG** (WebP works on most but not all crawlers)158- **Accessible via GET** with no authentication159160```bash161# Verify your OG image is reachable and correct size162curl -sI https://www.yourdomain.com/images/og/home.jpg | grep -i "content-type\|content-length\|status"163```164165---166167## Platform-Specific Notes168169### Facebook / Meta170- Caches aggressively — use the [Sharing Debugger](https://developers.facebook.com/tools/debug/) to force recrawl171- Minimum image: 200×200px (but use 1200×630 for quality)172- Needs: `og:title`, `og:description`, `og:image`, `og:url`173174### X / Twitter175- Use `twitter:card = summary_large_image` for full-width images176- `twitter:image` must be an absolute URL177- Use the [Card Validator](https://cards-dev.twitter.com/validator) to test178179### LinkedIn180- Caches hard — use [Post Inspector](https://www.linkedin.com/post-inspector/) to refresh181- Respects `og:` tags; ignores `twitter:` tags182- Image must be ≥1.91:1 aspect ratio183184### WhatsApp / Telegram185- Read OG tags on first share; cache can last hours186- Re-share after a few hours for the cache to clear naturally187188### Slack / Discord189- Both use OG tags; both cache190- Discord also supports `og:type = article` for richer embeds191192---193194## Debugging Social Previews195196### 1. Check raw HTML for tags197```bash198curl -s https://www.yourdomain.com/blog/my-post | grep -i "og:\|twitter:"199```200If tags don't appear → they're being added by JavaScript (not crawlable). Fix: move to `export const metadata` or `generateMetadata`.201202### 2. Validate with platform tools203204| Platform | Tool |205|----------|------|206| Facebook | https://developers.facebook.com/tools/debug/ |207| LinkedIn | https://www.linkedin.com/post-inspector/ |208| Twitter/X | https://cards-dev.twitter.com/validator |209| General | https://metatags.io |210211### 3. Force cache refresh212After deploying fixes, paste the URL into each platform's debugger and click "Fetch new scrape information" (or equivalent).213214---215216## Social Metadata Checklist217218- [ ] `metadataBase` set in root layout219- [ ] All shareable pages use shared `buildSocialMetadata` helper220- [ ] OG image URLs are absolute (start with `https://`)221- [ ] `secureUrl` set equal to `url` in OG image block222- [ ] Image is 1200×630px, under 8MB, HTTPS223- [ ] `twitter:card` is `summary_large_image` (not `summary`)224- [ ] Image alt text present225- [ ] Tags visible in raw HTML (not JavaScript-rendered)226- [ ] All platform debuggers show correct preview227- [ ] Cache refreshed on all platforms after deployment228229## Limitations230231- Cannot force immediate cache refresh on every social platform; some previews may remain stale after a correct fix.232- Requires publicly reachable deployed URLs for reliable validation with platform debuggers.233- Does not replace brand, accessibility, or legal review of image text, alt text, and preview copy.