MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Metadata API: Dynamic SEO, OpenGraph Tags & Sitemap Generation0%
Study Materials
Next.js 15Progress 0%
1.1Next.js 15 Overview & App Router vs Pages Router Architecture1.2Core File Conventions: page.tsx, layout.tsx, template.tsx & not-found.tsx1.3Dynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))1.4Streaming UI with loading.tsx and Suspense Boundaries
4.1API Route Handlers (route.ts): Building RESTful Microservices4.2Middleware.ts: Route Protection, Redirects, Cookies & Geolocation4.3Authentication with NextAuth / Auth.js & JWT Session Management4.4Metadata API: Dynamic SEO, OpenGraph Tags & Sitemap Generation4.5Production Optimization, Dockerization & Vercel Cloud Deployment
HomeTutorialsNext.js 15Metadata API: Dynamic SEO, OpenGraph Tags & Sitemap Generation
Production Optimization, Dockerization & Vercel Cloud Deployment

Metadata API: Dynamic SEO, OpenGraph Tags & Sitemap Generation

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Search Engine Optimization (SEO) and social media link previews are vital for digital reach. Next.js 15 features the built-in Metadata API, allowing developers to define static or dynamic SEO tags, OpenGraph images, Twitter cards, and programmatic sitemaps directly through type-safe TypeScript interfaces.


1. Static Metadata

Define static metadata by exporting a metadata object from any layout.tsx or page.tsx:

1// app/courses/page.tsx
2import type { Metadata } from 'next';
3 
4export const metadata: Metadata = {
5 title: 'Full-Stack & Data Analytics Courses | MSK Institute',
6 description: 'Explore comprehensive certification programs in web development, Python, and AI.',
7 keywords: ['full-stack web development', 'react', 'next.js', 'mongodb', 'python'],
8 openGraph: {
9 title: 'Master Modern Tech with MSK Institute',
10 description: 'Job-ready curriculum taught by industry leaders.',
11 url: 'https://mskinstitute.com/courses',
12 siteName: 'MSK Institute',
13 images: [
14 {
15 url: 'https://mskinstitute.com/images/og/courses-banner.jpg',
16 width: 1200,
17 height: 630,
18 alt: 'MSK Institute Courses'
19 }
20 ],
21 locale: 'en_IN',
22 type: 'website'
23 },
24 twitter: {
25 card: 'summary_large_image',
26 site: '@mskinstitute'
27 }
28};

2. Dynamic Metadata with generateMetadata()

For dynamic pages (e.g., /courses/[slug]), metadata depends on database content. Export an async generateMetadata() function:

1// app/courses/[slug]/page.tsx
2import type { Metadata, ResolvingMetadata } from 'next';
3import { getCourseBySlug } from '@/lib/courses';
4 
5interface Props {
6 params: Promise<{ slug: string }>;
7}
8 
9export async function generateMetadata(
10 { params }: Props,
11 parent: ResolvingMetadata
12): Promise<Metadata> {
13 const { slug } = await params;
14 const course = await getCourseBySlug(slug);
15 
16 if (!course) {
17 return { title: 'Course Not Found | MSK Institute' };
18 }
19 
20 return {
21 title: `${course.title} | MSK Institute`,
22 description: course.shortDescription,
23 openGraph: {
24 title: course.title,
25 description: course.shortDescription,
26 images: [course.featuredImageUrl || '/images/default-course-og.jpg']
27 }
28 };
29}

3. Programmatic Sitemaps: sitemap.ts

Search engines discover your entire content catalog through a sitemap.xml. Create app/sitemap.ts to generate dynamic sitemaps automatically:

1// app/sitemap.ts
2import { MetadataRoute } from 'next';
3import { getAllCourses } from '@/lib/courses';
4 
5export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
6 const baseUrl = 'https://mskinstitute.com';
7 const courses = await getAllCourses();
8 
9 const courseEntries: MetadataRoute.Sitemap = courses.map(course => ({
10 url: `${baseUrl}/courses/${course.slug}`,
11 lastModified: new Date(course.updatedAt || Date.now()),
12 changeFrequency: 'weekly',
13 priority: 0.8
14 }));
15 
16 return [
17 {
18 url: baseUrl,
19 lastModified: new Date(),
20 changeFrequency: 'daily',
21 priority: 1.0
22 },
23 {
24 url: `${baseUrl}/courses`,
25 lastModified: new Date(),
26 changeFrequency: 'daily',
27 priority: 0.9
28 },
29 ...courseEntries
30 ];
31}

Next.js automatically serves this at /sitemap.xml!


Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
Which function is used to generate dynamic SEO metadata based on database content for dynamic route segments?
Question 2
What is the standard recommended aspect ratio and resolution for OpenGraph preview images?
Question 3
What file convention in the app/ directory automatically generates a standardized sitemap.xml for search engines?
Question 4
How does Next.js handle metadata declared in a parent layout.tsx versus a child page.tsx?
Question 5
Why should you avoid fetching the same database record twice if both generateMetadata() and the page component need it?

Next Lesson

Production Optimization, Dockerization & Vercel Cloud Deployment

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Authentication with NextAuth / Auth.js & JWT Session ManagementProduction Optimization, Dockerization & Vercel Cloud Deployment

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Next.js 15 with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext