OG Images & Social Sharing for AI Coders | SheCodes
Intermediate 6 min read

OG Images & Social Sharing for AI Coders

Make your links look great when people share them. The single biggest free marketing trick.

In this chapter

  • What an OG image is and why it matters more than you think
  • How to add a static OG image to your site in 2 minutes
  • How to generate dynamic OG images for every page automatically
  • How to debug and refresh cached OG images

Why OG Images Are a Cheat Code

When someone pastes your link into a tweet, a Slack message, or an iMessage, the platform shows a preview card. That card has three things: a title, a description, and a big image. The image takes up 70% of the visual real estate.

Live example
Without an OG image
[broken / no image]
Your Site
shecodes.io/books
Looks broken. People scroll past.
With a great OG image
SheCodes Books
SheCodes Books: The AI Coder's Library
shecodes.io/books
Looks legit. People click.

The 2-Minute Static OG Image

The simplest version: one OG image for your whole site. Make it once in Figma or Canva, save it, and you're done.

  1. 1
    Open Figma or Canva. Create a 1200×630 frame.
  2. 2
    Add your logo, your tagline, and a brand-y background. Keep text big: small text is unreadable in previews.
  3. 3
    Export as PNG (or JPG for smaller file size).
  4. 4
    Save it to /public/og-image.png in your project.
  5. 5
    Add it to the metadata in app/layout.tsx (your AI tool can do this in one prompt).
ADD A STATIC OG IMAGE

“I have an image at /public/og-image.png that's 1200×630. Use it as the default preview image for my whole site (the one that shows up when someone shares any page on social media or in a message app). Include a short title, description, and alt text so it looks good on Twitter, LinkedIn, Facebook, and iMessage.”

Dynamic OG Images: One Per Page

Static is fine for the homepage. But if you have a blog or a product catalog, you want a unique image for each page, with the post title or product name baked in.

Next.js has a built-in feature for this called opengraph-image.tsx. You write a tiny React component that returns an image, and Next generates a real PNG on demand. No image editor needed.

How dynamic OG works in Next.js

  1. You create a file at app/blog/[slug]/opengraph-image.tsx
  2. Inside, you write a function that returns JSX (your image layout)
  3. Next renders it as a 1200×630 PNG when someone shares the URL
  4. The PNG is cached automatically: fast on every share after the first
ADD DYNAMIC OG IMAGES TO MY BLOG

“Every blog post on my site should get its own custom preview image (the one that shows up when someone shares the post on social media). Make each image 1200×630 and include the post title (nice and large), the author name, the publish date, and my brand logo. Use a purple gradient background with white text and my Bricolage font. Generate these automatically for every post.”

The Meta Tags You Need

OG images don't work on their own: they need specific HTML meta tags so platforms know where to find them. Next.js handles this through the metadata API.

The 6 tags every page needs

  • og:title the headline shown in the preview
  • og:description 1-2 lines below the title
  • og:image URL of the 1200×630 image
  • og:url canonical URL of the page
  • twitter:card "summary_large_image"
  • twitter:image same as og:image

You don't write these by hand. Next.js generates them from the metadata object you export from each page.

Design Rules for OG Images

Most OG images look bad because they break one of these rules. Follow them and yours will stand out.

Make text huge Headline should be at least 60px. Subtitle 30px. People see it as a thumbnail: small text is invisible.
High contrast Light text on dark background or vice versa. Never gray text on a gray background.
One focal point Don't cram in 5 things. Pick the headline OR the product photo, not both.
Brand color always visible Use your signature color in every OG image. Builds recognition over time.
No tiny logos in the corner If the logo matters, make it big. If not, leave it off.
Test in dark mode iMessage shows previews on a dark background. Make sure yours doesn't disappear.

Debugging Cached Previews

You updated your OG image. You shared the link. The old image is still showing. Welcome to caching hell.

Force-refresh your previews

  • X (Twitter): X no longer has a card preview tool. Paste the link into a new post to see the preview, and add ?v=2 to the URL to skip the old cached image
  • LinkedIn: linkedin.com/post-inspector, paste URL, click Inspect
  • Facebook: developers.facebook.com/tools/debug, paste URL, click "Scrape Again"
  • iMessage / Slack: add a fake query parameter (?v=2) to the URL

Common Gotchas

Image doesn't show up at all

Your og:image URL is relative (/og.png) instead of absolute (https://yoursite.com/og.png). Platforms need the full URL.

Image works on X but not LinkedIn

LinkedIn reads the og: tags, not the twitter: ones. Make sure og:image is a full URL and at least 1200×627, then re-check it in LinkedIn Post Inspector.

Custom font doesn't render in dynamic OG

ImageResponse can't use Google Fonts at runtime. Bundle the font file (.ttf/.otf) in your project and load it manually.

Old image keeps showing after update

Aggressive caching. Use the platform debugger above to force a refresh, or change the filename.

Real World Example: Making your blog go viral on X

You write a great blog post and tweet a link. Without an OG image, your tweet looks broken: just a URL. With a custom OG image showing the post title in big bold letters, your tweet stops the scroll and gets clicks. The fix is one prompt that creates a dynamic OG image generator for every blog post in your project.

Build this with AI

“Add dynamic OG image generation to every blog post in my Next.js project. Posts live at /blog/[slug] and the data comes from my posts table in Supabase. Each OG image should be 1200×630, show the post title in 72px Bricolage, the author name and publish date below in 24px, and my brand logo in the bottom right. Use a purple-to-pink gradient background. Use ImageResponse from next/og.”

Prompt This

OG IMAGE FOR EVERY PRODUCT PAGE

“My product pages live at /products/[slug]. Generate a dynamic OG image for each one showing the product photo on the left and the product name + price on the right. Use my brand colors. Cache aggressively.”

ADD A SHARE BUTTON

“On every blog post page, add a row of share buttons (X, LinkedIn, Facebook, copy link). They should pre-fill the post title and URL when clicked. Make sure the X share also includes my @handle for attribution.”

OG IMAGE PREVIEW IN MY CMS

“In my admin area where I edit blog posts, show a live preview of the OG image as I type the title. It should look like a real X card so I can see what the share will look like before publishing.”

Frequently Asked Questions

What is an OG image?

OG (Open Graph) images are the preview images that show up when someone shares your link on X, LinkedIn, Slack, iMessage, WhatsApp, anywhere. A good OG image is the difference between a click and a scroll-past.

What size should my OG image be?

1200×630 pixels. That's the magic number for X, LinkedIn, Facebook, and most platforms. If you go smaller it looks pixelated. If you go bigger, the file is wasteful.

Do I need a different OG image for every page?

Ideally yes. The homepage gets a brand image. Each blog post gets one with the post title. Each product page gets one with the product. Frameworks like Next.js make this automatic with one API route.

Why doesn't my new OG image show up when I share?

Caching. X, LinkedIn, and Facebook cache OG images aggressively. Use LinkedIn Post Inspector or the Facebook Sharing Debugger to force a refresh. X has no preview tool any more, so check it in the post composer or add ?v=2 to the URL.