Meta Data in NextJS
🏷️ Meta Data in Next.js
Next.js provides multiple ways to add meta data to your pages, which is essential for SEO, social sharing, and browser behavior.
📌 1. Adding Meta Data Using <Head> Component
Next.js has a built-in next/head component to manage metadata dynamically.
🔹 Basic Usage (title and meta tags)
<> <Head> <title>My Next.js App</title> <meta name="description" content="A powerful Next.js application" /> </Head> <Component {...pageProps} /> </> );}export default MyApp;
✅ Applies metadata to all pages by default
📌 6. Meta Data in app/ Directory (Next.js 13+ with App Router)
For projects using the App Router, add metadata in layout.js:
export const metadata = { title: "Next.js SEO", description: "Improve SEO with Next.js metadata.", openGraph: { title: "Next.js SEO", description: "SEO optimization in Next.js.", images: ["/og-image.jpg"], },};
✅ Built-in metadata support for Next.js 13+
📌 7. Best Practices for SEO Optimization
✔️ Use unique title and description for each page
✔️ Add Open Graph and Twitter meta tags for social sharing
✔️ Use getServerSideProps or getStaticProps for dynamic meta data
✔️ Place global meta tags inside _app.js or layout.js