Next.js Discord

Discord Forum

How can i add page specific metadata?

Answered
Arboreal ant posted this in #help-forum
Open in Discord
Avatar
Arboreal antOP
i currently have this in my layout file
  export const metadata = {
    title: 'test',
    description: 'test',  
    'theme-color': "#20c997"
  }

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head>
        <meta name="theme-color" content="#20c997"/>
      </head>
      <body className={inter.className}>
        <UserProvider>
          <NavBar/> 
        {children}
        </UserProvider>  
      </body>
    </html>
  );
}
so i have 2 questions, first how can i make this metadata apply on all pages that dont have specific metadata defined, and my 2nd question is do i have to make a seperate meta tag in the return to add a 'theme-color': "#20c997" because it doesnt work if i put it in with the rest of the metadata
Answered by Jesse677
the metadata in your layout will only be run if you don't have explicit meta data in one of your pages
View full answer

9 Replies

Avatar
You don't really need theme color in metadata, it's a bit extra
Avatar
the metadata in your layout will only be run if you don't have explicit meta data in one of your pages
Answer
Avatar
@Arboreal ant
Avatar
@Jesse677 You don't really need theme color in metadata, it's a bit extra
Avatar
Arboreal antOP
ah, okay, but is it posible to add the color? since the - is causing an error
Avatar
what error
you shouldn't get an error for not adding color
if you really need it then I suppose you could use the meta tag
Avatar
@Jesse677 you shouldn't get an error for not adding color
Avatar
Arboreal antOP
never mind
welp i guess that answers my question, thank you