Next.js Discord

Discord Forum

Next.js script tag

Answered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
Hello, I'm currently updating a project to the latest version of Next.js and encountering difficulty converting meta tags. In the old version, meta tags were managed within a component file. To adapt, I've created a generateMetadata function to handle these meta tags in accordance with the latest Next.js version.

However, I'm stuck on how to incorporate the logic for adding script tags into the generateMetadata function, which was previously managed in a separate file as provided below.

1st file containing the old logic of Meta tags and second one is containing Nexi.js 14 Metadata API.
Answered by joulev
the script part is the same, so you also have a component where you put the <script> component there, then use that component in the pages that you need, or in the root layout if you want it in all pages
View full answer

5 Replies

Answer
@joulev the script part is the same, so you also have a component where you put the `<script>` component there, then use that component in the pages that you need, or in the root layout if you want it in all pages
Asian black bearOP
Ok thanks, but that first attached file will removed in future so that I need to cover that <script> inside generateMetadata function.So how can I do that?
@joulev you can't do it, you need to use a react component
Asian black bearOP
OK, I added the <script> inside the NewCarItem component, so I want to confirm if that's correct. Since the latest version of Next.js doesn't support the <Head> component, is it necessary to include the <Head> component if I want to add that script inside the component?