Skip to content

Headless CMS Internal Linking: Where Links Live and How to Ship Them

By Lazarina Stoy · 12 min read
Headless CMS Internal Linking: Where Links Live and How to Ship Them: illustration of pages connected by internal links. An MLforSEO guide by Lazarina Stoy.

On a WordPress site, an internal linking plugin can change a page on its way to the reader. On a headless site there is usually nothing in that spot. The content lives in a CMS such as Contentful, Sanity or Storyblok, a front end such as Next.js or Astro turns it into pages, and those pages are often built ahead of time and served as files. So when a team moves stacks, the same question comes up every time: where do our internal links actually go now, and how do we add them at scale?

I spent the last few weeks on exactly that while building the headless lesson of a course module, and the most useful thing I found was a little alarming. When I ran each CMS’s official HTML renderer on a sample post with an editor-added link to a glossary page, none of them produced the link I wanted out of the box. Two of them dropped the link entirely. If your team has been adding internal links in a headless CMS for a year, it’s worth ten minutes to check they reach the page.

This guide covers where links live in a headless stack, how each of the three CMSs stores them, the options and tools for adding links at scale, how to check the result, and the gaps I found in what currently ranks for this topic.

Free cheat sheet

Rich text internal links cheat sheet: Contentful, Sanity and Storyblok: a two-page PDF on how each CMS stores an in-body link, how to resolve it to a real <a href>, where each renderer goes wrong by default, plus tested resolver code.

On this page
  1. What changes when you go headless
  2. Three places an internal link lives in a headless stack
  3. How Contentful, Sanity and Storyblok store an internal link
  4. Your options for adding internal links at scale
  5. How to check your internal links actually shipped
  6. What the current guides leave out
  7. Where to start
  8. Frequently asked questions

What changes when you go headless

Google’s rule for links hasn’t changed: it can follow a link when it’s an <a> element with an href, as its documentation on crawlable links puts it. What changes is who is responsible for producing that element. In a traditional CMS the theme and plugins do it. In a headless build your developers do, in code, for every kind of link.

WordPress VIP makes the same point in its piece on headless CMS SEO: related-content modules and breadcrumbs come with a WordPress theme, and a headless build has to recreate them with custom code. Its warning is that internal links you haven’t mapped before a migration can disappear at relaunch, a risk worth planning for in any site migration.

The good news is that a headless stack gives you more control once you know where to look. Links can point at entry ids instead of typed URLs, so they survive slug changes. Related blocks can be computed at build time from your own data. And every link can be tested before a page goes live.

Three cards: reference fields, rich-text links and build-time blocks, each with where it is edited, how it breaks and how to undo it, all feeding into a bar reading: all three only count once they are an a href in the HTML the server sends
The three places an internal link lives in a headless stack. Each is edited in a different place and needs its own check.

Whatever your CMS and framework, internal links end up in one of three places. Each one is edited by different people and fails in its own way, so it helps to audit them separately.

  • Reference fields. Fields that store the ids of other entries: “related articles”, category, author, a parent page. Editors pick the entries; a component renders them as a list of links. These are the headless version of a curated related-posts box.
  • Rich-text links. The link inside a sentence, stored as structured data in the body field. These are usually your most valuable contextual links, and the ones most likely to break quietly in the renderer.
  • Build-time blocks. Related posts, sibling pages, breadcrumbs and “mentioned in” lists that the front end generates when the site is built, from tags, references or embeddings. Nothing is stored in the CMS.

Static sites built from Markdown add a fourth, simpler case: links typed into the file as plain Markdown. They behave like rich-text links that are already HTML, with Git as your version history.

Table of Contentful, Sanity and Storyblok: how each stores an internal link, what its official HTML renderer outputs by default (a debug span, an unknown-mark span, a relative link) and the crawlable a href after adding a link renderer
Same glossary link, three CMSs: the official renderers' default output versus the output with a link renderer (run on sample data, 5 December 2026, with @contentful/rich-text-html-renderer 17.2.3, @portabletext/to-html 6.0.0 and @storyblok/richtext 5.5.2).

All three store an in-body link as data that points at another entry. That’s a strength: the link follows the entry, not its URL. It also means your front end must look up the target and build the URL, and the default renderers don’t always do it the way you’d expect.

Contentful: an entry-hyperlink node

Contentful’s rich text is a JSON tree, described in its rich text documentation. A link to another entry is an inline node of type entry-hyperlink that holds the target entry’s id in data.target.sys.id, with the anchor words inside the node. The delivery API returns the linked entries alongside the post (in includes.Entry on REST, or a links object on GraphQL), and your code maps the id to a slug.

The trap: Contentful’s HTML renderer needs a rule for this node type. Without one, on my test it printed <span>type: entry-hyperlink id: 4kMeansTerm</span> in place of the link, and the anchor text was gone. The fix is a single renderNode entry for INLINES.ENTRY_HYPERLINK.

Sanity: an annotation with a reference

Sanity’s Portable Text keeps text in spans. The linked words become their own span, and a key on that span points to an annotation in the block’s markDefs. Internal links are a custom annotation you define in your schema, usually called internalLink, holding a reference to the target document. The official guide to internal links in Portable Text still ranks first for this question; it dates from 2019, so pair it with the current docs on presenting Portable Text.

The trap: if your serializer has no component for that annotation, @portabletext/to-html wraps the words in a span with an “unknown mark” class and logs a warning. The page shows the text, so nobody notices the link is missing. The fix is to dereference the target in GROQ (reference->{_type, "slug": slug.current}) and add a mark component that returns an <a href>.

Storyblok: a link mark with a uuid

Storyblok’s Richtext field stores a link mark on the anchor text, with linktype: "story", the target story’s uuid and an href holding the story’s slug as saved. Its field documentation describes the same pattern for Link fields, where cached_url is the slug at the latest save.

The trap: the saved slug has no leading slash, so a renderer that prints it as it is produces a relative link that resolves against the current folder. Storyblok’s own issue #146 describes it, and the current @storyblok/richtext renderer still did it on my test. Resolving the uuid against the Links API gives you each story’s current path, which also covers stories that moved after the link was saved.

One more thing these formats have in common: a typed URL inside rich text (Contentful’s plain hyperlink, a Sanity link annotation, a Storyblok url link pointing at your own site) behaves like any hard-coded link. It works until the slug changes. If an audit finds many of them, converting them to entry links is a worthwhile clean-up.

Six option cards for adding internal links to a headless site, from editors linking in the CMS to a JavaScript snippet, each tagged with whether the link is in the server HTML and whether editors see it
Six ways to add internal links to a headless site, from the safest default to the last resort.

Once you know where links live, the options for adding more of them fall into six groups. I’ve ordered them from the one I’d start with to the one I’d use only when nothing else is available.

OptionWhere the link ends upGood forWatch out for
Editors link in the CMSRich text and reference fieldsContextual links that need judgementA renderer that doesn’t output a real link
Build-time componentsThe front end’s templatesRelated posts, siblings, breadcrumbs, “mentioned in” listsBlocks that fetch their items in the browser
Rules at build timeA step that edits the rendered HTMLGlossary terms and names that should always link to one pageOver-linking: cap each rule per page
Write back through the APIThe stored contentApproved sentence-level links, at volumeNeeds backups, a dry run and an undo log
Edge rewriteHTML changed by a worker in front of the CDNSites where the CMS and code are closed to youHard to debug, invisible to editors
JavaScript snippetThe browser, after the page loadsQuick trialsLinks missing from the server HTML

A few notes from building and testing these.

Build-time components are where most headless sites should start. Next.js renders its <Link> component as an <a href>, so related posts built in a server component are in the HTML. Astro’s content collections let you store editor-picked related entries with reference() and resolve them with getEntries() at build time. Hugo goes furthest out of the box: its related content feature builds an index from your front matter and lists related pages in a template with no plugin. Eleventy collections do the same job with a few lines of code. If you already compute cosine similarity between pages for an audit, the same scores can drive these blocks.

Rules at build time are the headless version of an auto-linking plugin. A step after rendering reads a rules file (“link this term to that page, once per page”) and edits the HTML, skipping headings, existing links and code. The CMS never changes, so switching a rule off is one rebuild. I ran this on four of my own articles with ten glossary rules (one switched off) and it added fifteen links, six of them on one page, which is exactly why each rule needs a per-page cap and a preview before it ships.

Writing back through the API is the right home for links someone approved one by one, because editors then see them in the CMS and they survive a redesign. Every CMS here has a management API that can do it, and each has a safety catch worth using: Contentful’s version header rejects a write if anyone saved since you read, and Sanity’s mutation API has a dryRun option and revision locking. The rule that matters most is to add a link as a node or mark by walking the document, never with find and replace on the JSON.

Third-party tools mostly sit in the suggest-and-apply space for headless sites. LinkBoss, which ranks for this query, says on its all-CMS page that it reads your published pages through a scraper you connect and can’t edit a custom site directly, so suggested links wait as changes you apply by hand or through an AI assistant connected over MCP. Tools that inject links with a JavaScript snippet are quick to try, but the links they add aren’t in the HTML your server sends, so check with your own crawl what search engines can see before you rely on them.

A link that exists in the CMS but not in the HTML doesn’t help anyone. Makers’ Den’s guide to headless CMS SEO puts the check where it belongs: on publish, rebuild, then validate the generated HTML for broken internal links before release. Here’s the routine I use.

  • Look at the server HTML. Fetch a page the way a crawler first sees it and count the links you expect. If the number is zero, the link is either rendered in the browser or not rendered at all.
  • Audit the stored links. Export the JSON your front end reads and list every rich-text link with the href it should get. Links to unpublished or deleted entries show up here before they show up as gaps on the page.
  • Fail the build on broken links. Run a link checker such as lychee, linkinator or html-proofer on the build output in CI. Astro has no built-in link validation (the roadmap discussion lists community options), and Starlight sites can use starlight-links-validator.
  • Crawl with rendering on and off. Compare the outlinks a crawler finds with JavaScript off and on. Anything that shows up only in the rendered crawl is being added by scripts in the browser. A crawler with custom extraction works well here; the setup is the same as in my guide to scraping page content with Screaming Frog.
curl -s https://www.example.com/blog/a-post/ | grep -c 'href="/glossary-term/'

AstroSEO’s guide to auditing internal links in Astro has the right instinct here: audit the built output, not the source, and compare it with the links you intended to have.

What the current guides leave out

Before writing this, I read the pages that rank for headless internal linking. Most are useful on strategy and thin on mechanics. Three gaps stood out:

  • How links are stored and resolved. None of the strategy articles show what a rich-text internal link looks like in Contentful, Sanity or Storyblok, or how it becomes a link on the page. The answers are spread across official docs, GitHub issues and Stack Overflow.
  • Bulk edits with a safety net. No headless page I read covers adding links through a management API with a dry run and a way back. That is the step most likely to damage content at scale.
  • Whether it worked. Makers’ Den is one of the few pages that checks the generated HTML, and none of the internal linking tool comparisons I read gives a method for measuring the impact.

Measuring is a topic of its own, and the approach is the same on any stack: record the date each link went live, then compare the linked pages with a group you left alone. I cover the wider set of automation methods, measurement included, in 10 ways to automate internal linking with AI.

Where to start

  1. Pick three pages with links you know about and check the server HTML for them.
  2. Find out which renderer your front end uses for rich text and whether it has a link rule for internal links.
  3. List your reference fields and build-time blocks, and confirm each one renders on the server.
  4. Add a link checker to your build so the next broken internal link fails loudly.
  5. Only then add new links: build-time blocks and rules first, approved write-backs second. If you’re planning the structure those links should support, my guides to blog and site architecture and search intent-first architecture are a good place to begin.

Free cheat sheet

Rich text internal links cheat sheet: how Contentful, Sanity and Storyblok store an internal link, how to turn it into a real link, the default traps, and the safe way to write links back, with tested code on GitHub.

If you want the whole build, from a scored list of link opportunities to links shipped on WordPress, headless sites, Shopify and Webflow with dry runs, undo logs and measurement, that’s what AI-powered Internal Linking Audit and Automation covers. Sam Torres leads the course, and I wrote Module 5, “Shipping Links in Your CMS: WordPress and Beyond”, where the headless lesson walks through each step in this post with your own link menu and the course scripts. This guide and the free cheat sheet stand on their own if you’d rather build it yourself.

Frequently asked questions

Are internal links in a headless CMS bad for SEO?

No. Search engines see the HTML your front end produces, and a headless site can produce exactly the same links as any other. The risk is in the plumbing: a renderer that doesn’t output an <a href>, or blocks that only load in the browser. Check the server HTML and you’ll know.

How do I stop internal links breaking when a slug changes?

Link to entries, not URLs. Contentful entry links, Sanity references and Storyblok story links all point at an id, so the front end builds the current URL at build time. Typed URLs inside rich text are the ones that break, and they need redirects when slugs change.

Can I automate internal linking in Contentful, Sanity or Storyblok?

Yes, in three ways: generate related blocks at build time, apply linking rules to the rendered HTML, or write approved links into the content through the management API. The first two never change the CMS. The third needs backups, a dry run and an undo log, because a saved link has no off switch.

Should I use a JavaScript internal linking tool on a headless site?

I’d use one only as a trial. Links injected in the browser aren’t in the HTML the server sends, and editors can’t see them in the CMS. If a tool’s suggestions are good, apply them where they last: in the content or in a build-time component.

Does Next.js Link create crawlable links?

Yes. The <Link> component from next/link renders an <a> element with an href, so links rendered on the server are crawlable. The usual problem is upstream: the component never receives a valid href because the rich-text link wasn’t resolved.

MLforSEO Academy

Pick your learning path

Start with the course that goes deepest on this article, then more courses taught by Lazarina Stoy, most relevant first.

Recommended with this article

AI-powered Internal Linking Audit and Automation

by Sam Torres with Lazarina Stoy

Audit how your site links to itself, find the pages and entities your links leave out, and plan and automate the fixes with AI at scale.

View course · €350 →

Introduction to Machine Learning for SEO

by Lazarina Stoy

Go from zero to running your first ML workflows for SEO: classification, clustering, entity extraction, fuzzy matching and content transformation.

View course · €250 →

Semantic AI-powered SEO Keyword Research

by Lazarina Stoy with Beatrice Gamba

Build a semantic keyword universe and an automated content-brief workflow, from query understanding through SERP analysis to delivery.

View course · €400 →

AI Search & LLMs: Entity SEO and Knowledge Graph Strategies for Brands

by Beatrice Gamba with Lazarina Stoy

Win in both traditional Google and LLM-driven search by mastering entities, brand recognition, and knowledge graph integration.

View course · €200 →

The AI-powered Entity Audit

by Lazarina Stoy

A complete, repeatable entity audit you can run on any site. Built on the 5Cs of entity representation and demonstrated end to end on a real, unedited site.

View course · €150 →
Bundle & save up to €200 →See all 6 courses →Already an Academy member? Use Community30 for 30% off your next course or bundle.