Different Title and Page desc per page
Answered
Asian black bear posted this in #help-forum
Asian black bearOP
So in normal html inside the <head> youd add things like title, description, favicon, and meta data. How can I do this inside Node.js jsx? I want for the home page to be MyBusines- Home, contact page would be something like MyBusiness- Contact us etc with custom meta data too?
29 Replies
@ncls. https://nextjs.org/docs/app/building-your-application/optimizing/metadata
Asian black bearOP
so would I follow Dynamic Metadata?
@Asian black bear so would I follow Dynamic Metadata?
Your project sounds like Static Metadata should be enough, isn't it?
@ncls. Your project sounds like Static Metadata should be enough, isn't it?
Asian black bearOP
I just want to add a custom title, description and meta data for each page if that makes sense?
Yeah, and I suppose each page has it's own file?
So something like this:
Then every
So something like this:
/app
┃ /page.tsx
┣ /contact
┃ ┗ /page.tsx
┗ /about
┗ /page.tsx
Then every
page.tsx
file can export it's own const
named metadata
as [described in the Docs](https://nextjs.org/docs/app/building-your-application/optimizing/metadata#static-metadata) and everything should work@ncls. Yeah, and I suppose each page has it's own file?
So something like this:
/app
┃ /page.tsx
┣ /contact
┃ ┗ /page.tsx
┗ /about
┗ /page.tsx
Then every `page.tsx` file can export it's own `const` named `metadata` as [described in the Docs](https://nextjs.org/docs/app/building-your-application/optimizing/metadata#static-metadata) and everything should work
Asian black bearOP
mine is .jsx
so would that still be fine?
so would that still be fine?
Yes
Asian black bearOP
so just put this in every page?
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: '...',
description: '...',
}
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: '...',
description: '...',
}
Yes, as long as they are server components, this should work
@ncls. Yes, as long as they are server components, this should work
Asian black bearOP
Does this look right?
@Asian black bear Does this look right?
Are you using app or pages router?
@ncls. Are you using app or pages router?
Asian black bearOP
app
@Asian black bear app
Then you can't use the
<Head>
componentAsian black bearOP
oh
@ncls. Do it like that
Asian black bearOP
right okay
@ncls. Do it like that
Asian black bearOP
So this is my code right now:
import Header from "./_components/Header";
import HomeBanner from "./_components/HomeBanner";
import FAQ from "./_components/FAQ";
import Footer from "./_components/Footer";
import type { Metadata } from 'next';
export const metadata: Metadata = {
title: 'Title',
description: 'Desc',
}
export default function Home() {
return (
<div>
<Header />
<HomeBanner />
<FAQ />
<Footer />
</div>
);
}
how do I add meta data?
You did
Asian black bearOP
no this
<!-- Primary Meta Tags -->
<title>Dreamality Interactive - The Home of Next Gen Games</title>
<meta name="title" content="Dreamality Interactive - The Home of Next Gen Games" />
<meta name="description" content="The Official Home for Dreamality Interactive." />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://dreamalityinteractive.com" />
<meta property="og:title" content="Dreamality Interactive - The Home of Next Gen Games" />
<meta property="og:description" content="The Official Home for Dreamality Interactive." />
<meta property="og:image" content="https://metatags.io/images/meta-tags.png" />
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content="https://dreamalityinteractive.com" />
<meta property="twitter:title" content="Dreamality Interactive - The Home of Next Gen Games" />
<meta property="twitter:description" content="The Official Home for Dreamality Interactive." />
<meta property="twitter:image" content="https://metatags.io/images/meta-tags.png" />
<!-- Meta Tags Generated with https://metatags.io -->
<!-- Primary Meta Tags -->
<title>Dreamality Interactive - The Home of Next Gen Games</title>
<meta name="title" content="Dreamality Interactive - The Home of Next Gen Games" />
<meta name="description" content="The Official Home for Dreamality Interactive." />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://dreamalityinteractive.com" />
<meta property="og:title" content="Dreamality Interactive - The Home of Next Gen Games" />
<meta property="og:description" content="The Official Home for Dreamality Interactive." />
<meta property="og:image" content="https://metatags.io/images/meta-tags.png" />
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content="https://dreamalityinteractive.com" />
<meta property="twitter:title" content="Dreamality Interactive - The Home of Next Gen Games" />
<meta property="twitter:description" content="The Official Home for Dreamality Interactive." />
<meta property="twitter:image" content="https://metatags.io/images/meta-tags.png" />
<!-- Meta Tags Generated with https://metatags.io -->
how do I add this to that?
@ncls. https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadata-fields
Asian black bearOP
My code isnt working:
import Header from "./_components/Header";
import HomeBanner from "./_components/HomeBanner";
import FAQ from "./_components/FAQ";
import type {Metadata} from 'next';
import Footer from "./_components/Footer";
export const metadata: Metadata = {
title: 'Title',
description: 'Desc',
}
export default function Home() {
return (
<div>
<Header />
<HomeBanner />
<FAQ />
<Footer />
</div>
);
}
saying syntax error
Show me the error then
Asian black bearOP
Ah, got it. You gotta remove the import line and the
: Metadata
since they are just for TypeScriptAsian black bearOP
import Header from "./_components/Header";
import HomeBanner from "./_components/HomeBanner";
import FAQ from "./_components/FAQ";
import Footer from "./_components/Footer";
export const metadata = {
title: 'Title',
description: 'Desc',
}
export default function Home() {
return (
<div>
<Header />
<HomeBanner />
<FAQ />
<Footer />
</div>
);
}
Exactly