Next.js Discord

Discord Forum

Schema data not outputting the Head?

Answered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
Hello,
I am trying to output some schema from my layout.jsx file. This appears to be possible https://nextjs.org/docs/app/building-your-application/optimizing/metadata#json-ld

layout.jsx
import Head from 'next/head';
const jsonLd = {
  '@context': 'https://schema.org',
  '@type': 'LocalBusiness',
  'name': companyData.companyName,
  etc etc
}

export default function RootLayout({ children }) {
  return (
    <html lang='en-GB'>
      <Head>
        <script
          type='application/ld+json'
          dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
        />
      </Head>
      <body className={DMSans.className}>

Currently nothing outputs 🤔 Some guidance would be great, thanks in advance…
Answered by joulev
just use the <script> tag directly in the page content
View full answer

7 Replies

are you using app or pages dir? (as the link you shared was for app dir)
next/head doesn't work in the app router
just use the <script> tag directly in the page content
Answer
thats what i was trying to understand out of the query
Masai LionOP
Sorry, yes, using app. How do I make sure the script ends up in the head without next/head?
Masai LionOP
Ah sorry, Next is clever enough to just put anything within a <head></head> in there
As joulev said,it is not required to be in the actual head