Skip to main content

Command Palette

Search for a command to run...

SEO in Next.js: Metadata, Open Graph & Social Sharing (Complete Guide)

Published
โ€ข3 min read
SEO in Next.js: Metadata, Open Graph & Social Sharing (Complete Guide)
G

I'm a Senior Front-End Engineer with 12+ years of experience in JavaScript-based technologies, UI architecture, and platform modernization. I have strong expertise in React.js, Next.js, TypeScript, and WordPress headless systems.

Search Engine Optimization (SEO) in modern web applications is no longer just about meta tags. With Next.js App Router, SEO has become declarative, dynamic, and extremely powerful โ€” if implemented correctly.

In this article, Iโ€™ll walk through:

  • How SEO works in Next.js (App Router)

  • Using the Metadata API correctly

  • Open Graph & Twitter cards for social sharing

  • Common mistakes developers still make

  • How I implemented SEO for my portfolio & blog


๐Ÿš€ Why SEO Matters for Frontend Developers

SEO is not just a marketing concern anymore.

As frontend developers, we control:

  • Page structure

  • Metadata

  • Performance (Core Web Vitals)

  • Social preview cards

  • Crawlability

A well-optimized Next.js site:

  • Ranks better

  • Gets higher LinkedIn / WhatsApp CTR

  • Looks professional when shared

  • Improves perceived quality of your portfolio


๐Ÿงฉ SEO in Next.js App Router (Quick Overview)

Next.js provides a Metadata API that allows you to define SEO at:

  • Global level (layout.tsx)

  • Page level (page.tsx)

  • Dynamic routes ([slug]/page.tsx)

This metadata is server-rendered and visible to search engines and social crawlers.


๐ŸŒ Global SEO Setup (layout.tsx)

This is where you define default SEO for your entire website.

export const metadata = {
  title: {
    default: "Gulshan Kumar - Senior React.js / UI Developer",
    template: "%s | Gulshan Kumar",
  },
  description: "Senior React.js developer with 12+ years of experience.",
  metadataBase: new URL("https://gulashan.vercel.app"),
  openGraph: {
    type: "website",
    title: "Gulshan Kumar Portfolio",
    description: "Modern frontend portfolio with blogs and tools",
    images: [
      {
        url: "/gulshan.png",
        width: 1200,
        height: 630,
      },
    ],
  },
  twitter: {
    card: "summary_large_image",
    creator: "@gulshankumar",
  },
};

โœ… This ensures every page has SEO fallback values.


๐Ÿ“ฐ Page-Level SEO (page.tsx)

For static pages like /blog or /speed-test, you can override metadata:

export const metadata = {
  title: "Blog",
  description: "Frontend engineering blogs on React and Next.js",
};

๐Ÿ”ฅ Dynamic SEO for Blog Posts ([slug]/page.tsx)

This is where Next.js really shines.

export async function generateMetadata({ params }) {
  const post = await fetchPost(params.slug);

  return {
    title: post.title,
    description: post.brief,
    openGraph: {
      title: post.title,
      description: post.brief,
      images: [
        {
          url: post.coverImage.url,
          width: 1200,
          height: 630,
        },
      ],
    },
    twitter: {
      card: "summary_large_image",
      title: post.title,
      description: post.brief,
      images: [post.coverImage.url],
    },
  };
}

๐Ÿ’ก This ensures:

  • Each blog post has unique SEO

  • Social platforms show the correct image & title

  • Better CTR when shared on LinkedIn, WhatsApp, X


๐Ÿ–ผ Open Graph Images (Most Common Mistake)

โŒ Mistake developers make:

  • Using relative URLs

  • Small images

  • Missing OG tags

โœ… Best practices:

  • Use absolute URLs

  • Image size: 1200 ร— 630

  • Use summary_large_image for Twitter


๐Ÿ”— Social Sharing: How Cards Are Generated

Important clarification:

Social cards are NOT controlled by your share buttons.

Platforms like:

  • LinkedIn

  • Facebook

  • WhatsApp

  • X

๐Ÿ‘‰ Fetch your page URL
๐Ÿ‘‰ Read HTML <head>
๐Ÿ‘‰ Extract OG & Twitter meta
๐Ÿ‘‰ Cache aggressively

Thatโ€™s why SEO metadata matters more than UI code.


๐Ÿง  Structured Data (JSON-LD)

To improve discoverability, add structured data:

{
  "@context": "https://schema.org",
  "@type": "Person",
  "name": "Gulshan Kumar",
  "jobTitle": "Senior React.js Developer",
  "url": "https://gulashan.vercel.app"
}

This helps Google understand who you are, not just what your site is.


๐Ÿ›‘ Common SEO Mistakes in Next.js

โŒ Relying on <Head> manually
โŒ Forgetting metadataBase
โŒ Using client components for SEO
โŒ Testing only on localhost
โŒ Ignoring social preview testing tools


โœ… Tools to Test Your SEO

  • LinkedIn Post Inspector

  • Facebook Sharing Debugger

  • Twitter Card Validator

  • Google Rich Results Test

  • Lighthouse SEO Audit


๐ŸŽฏ Final Thoughts

SEO in Next.js is no longer complex โ€” but it does require discipline.

If you:

  • Use Metadata API correctly

  • Generate dynamic SEO for blogs

  • Add proper Open Graph images

  • Structure your content well

Youโ€™ll get:
โœ… Better rankings
โœ… Higher social reach
โœ… Professional-grade portfolio

More from this blog

5 Performance Mistakes

7 posts