Skip to main content

Dec 2026 · Guide · ~8 min read

Next.js Metadata — Titles, Descriptions, and Canonical URLs

By Safdar Ali — frontend engineer, Bengaluru

I'm Safdar Ali. The metadata export on a page is what ends up in the head. A shared layout title with no page title means every URL looks the same in a search result. I set a title and description on each route that is meant to be indexed.

The canonical URL is the one you want indexed. Query-string copies and trailing-slash variants should point at it. This site sets metadataBase in the root layout and a canonical on the article. Without that, a rewritten host or a preview deployment can advertise the wrong origin.

Open Graph fields are the card when someone pastes the link. Use the same facts as the page, not a marketing line that the article does not support. A generated image is fine. A default image for every post is also fine if the title is specific.

Do not put a keyword list in the copy as a substitute. The description should be a sentence a person would click. I write it after the article, from the article, in one or two lines.

Unpublished or private routes should not be in the sitemap and should ask not to be indexed. A metadata title on a 404 that still says index, follow is how empty pages enter the index.

If this helped you

I publish free tutorials and write-ups like this in my spare time — no paywall on the guides. If it saved you an afternoon of trial and error, you can support the work:

More guides on safdarali.in — same author, production-focused.

"Talk is cheap. Show me the code."