GitHub|Since 2007
Step 17

SEO and Metadata

Configure dynamic meta tags to boost your search engine rankings and social media visibility.

14 min

Dynamic Metadata

Next.js makes SEO easy. For dynamic pages, we use the `generateMetadata` function to pull titles and descriptions directly from WordPress.

Implementation

export async function generateMetadata({ params }) {
  const post = await getPostBySlug(params.slug);
  return {
    title: `${post.title.rendered} | My Blog`,
    description: post.excerpt.rendered,
  };
}

This ensures that when your post is shared on Twitter or found on Google, it has the correct title, description, and preview image.

Comments and Discussion