How to add static or dynamic metadata to a NextJS page

Oscar de la Hera Gomez
A flower that represents NextJS with the text "Metadata" beneath it.

Add and export the generateMetadata function top of each page to add SEO to a NextJS page.

The following post explains how to add static or asynchronous metadata to pages within the app router of a NextJS project.

If you are not familiar with the NextJS app router, consult the link below.

If you wish to read the official documentation on adding metadata, consult the link below.

Static

A screenshot of the NextJS documentation showing how to add static metadata to pages.

To add static metadata, follow the example in the NextJS documentation.

Dynamic Metadata

A screenshot of VSCode showing a dynamic route within the student archive project.

For dynamic metadata, add the generateMetadata function at the top of your page.tsx file.

Make sure that it:

  • Is asynchronous.
  • Is exported.
  • Returns a Promise<Metadata>, where Metadata is imported as follows: import type { Metadata } from 'next';

Looking to learn more about NextJS, ReactJS or web development?

Search our blog to find educational content on NextJS, ReactJS and web development.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details