Rendered HTML
- What good looks like
- One accurate title, useful description, canonical, and main content in the page output
- If it fails
- Check Head export location, GraphQL data, and fallbacks
Use Gatsby's Head API for page metadata, verify generated HTML, and keep sitemap URLs aligned with published routes.
Use Gatsby's built-in Head export on pages and createPage templates to render page-specific title, description, canonical, and social metadata into generated HTML. Support for Head was added in gatsby@4.19.0; older projects need a compatible alternative. Set siteUrl, add gatsby-plugin-sitemap, then build and inspect both the generated HTML and the sitemap.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
Head export adds page-specific tags to the generated HTML. Gatsby's docs say support was added in gatsby@4.19.0. The Head function receives location.pathname, params (for matchPath pages), data from the page's GraphQL query, and pageContext, which makes it useful for CMS-backed templates created with createPage. Valid tags inside it are link, meta, style, title, base, script and noscript.Head from the page or its createPage template. Gatsby's docs say you can only define it inside a page (templates for createPage included), not in a component.pageContext for route-specific metadata. Add fallbacks for missing optional fields without repeating one generic title across every page.id when you need only one of them rendered: in a list of items with the same id, the last item wins and is used in the HTML.<html> and <body> attributes from Head needs gatsby@5.5.0, and reading React Context from wrapRootElement needs gatsby@5.6.0.export function Head({ data, location }) {
const page = data?.contentfulPage
const title = page?.seoTitle || page?.title || 'Example site'
const description = page?.seoDescription || page?.summary
const canonical = `https://www.example.com${location.pathname}`
return (
<>
<title>{title}</title>
{description && <meta name="description" content={description} />}
<link rel="canonical" href={canonical} />
</>
)
}Define siteUrl in siteMetadata using the canonical HTTPS origin. Gatsby's guide says it must be defined and not left empty; the plugin README says it is needed unless you set the resolveSiteUrl option.
Install gatsby-plugin-sitemap and include it in the plugins array in gatsby-config.js or gatsby-config.ts.
Run gatsby build && gatsby serve; the plugin only generates output in production mode. By default it writes sitemap-index.xml at the site root, plus a new sitemap-X.xml for every 45000 URLs (entryLimit). Point Search Console at https://www.example.com/sitemap-index.xml.
Check representative static and CMS-generated routes. Remove drafts, previews, duplicates, and routes that redirect or return errors.
module.exports = {
siteMetadata: {
siteUrl: 'https://www.example.com',
},
plugins: ['gatsby-plugin-sitemap'],
}If your pages come from a CMS, confirm that the Gatsby build created them before expecting the sitemap plugin to list them. By default the sitemap includes all of the site's pages except those you exclude via excludes; /dev-404-page, /404 and /offline-plugin-app-shell-fallback are always excluded. The default output gives every URL the same changefreq and priority, which Google ignores. The README recommends a custom serialize that supplies an accurate lastmod.
siteUrl, path normalization, and preview host configurationHead is composed through shared utilities, keep a single source of truth for title, description, and canonical data.See the Gatsby Head API, Gatsby sitemap guide, JavaScript SEO basics, and Google sitemap submission.
3 questions people ask next, answered from the sources on this page.
Gatsby has a built-in Head export for adding elements to the document head of a page. Support was added in gatsby@4.19.0, so check the project version before using it.
Export a named Head function from a page or page template, including templates created with createPage. Use queried data or page context for page-specific values.
Set siteUrl in siteMetadata, add gatsby-plugin-sitemap, and run a production build. The plugin writes sitemap-index.xml by default; check that its URLs resolve on the live site.
Run the free audit, then approve the fixes. Every change can be undone.